Last active
January 27, 2018 19:20
-
-
Save geoffgraham/7116b0856a75082c46a9891402b9da8a to your computer and use it in GitHub Desktop.
The Events Calendar - Yoast SEO - Prevent Yoast from changing Event Title Tags for Event Views (Month, List, Etc.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Prevent Yoast from changing Event Title Tags for Event Views (Month, List, Etc,) | |
add_action( 'pre_get_posts', 'tribe_remove_wpseo_title_rewrite', 20 ); | |
function tribe_remove_wpseo_title_rewrite() { | |
if ( class_exists( 'Tribe__Events__Main' ) && class_exists( 'Tribe__Events__Pro__Main' ) ) { | |
if( tribe_is_month() || tribe_is_upcoming() || tribe_is_past() || tribe_is_day() || tribe_is_map() || tribe_is_photo() || tribe_is_week() ) { | |
$wpseo_front = WPSEO_Frontend::get_instance(); | |
remove_filter( 'wp_title', array( $wpseo_front, 'title' ), 15 ); | |
remove_filter( 'pre_get_document_title', array( $wpseo_front, 'title' ), 15 ); | |
} | |
} elseif ( class_exists( 'Tribe__Events__Main' ) && !class_exists( 'Tribe__Events__Pro__Main' ) ) { | |
if( tribe_is_month() || tribe_is_upcoming() || tribe_is_past() || tribe_is_day() ) { | |
$wpseo_front = WPSEO_Frontend::get_instance(); | |
remove_filter( 'wp_title', array( $wpseo_front, 'title' ), 15 ); | |
remove_filter( 'pre_get_document_title', array( $wpseo_front, 'title' ), 15 ); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suggest adding a check to make sure the Yoast plugin is active, first and foremost.