Skip to content

Instantly share code, notes, and snippets.

@geoffgraham
Last active January 27, 2018 19:20
Show Gist options
  • Save geoffgraham/7116b0856a75082c46a9891402b9da8a to your computer and use it in GitHub Desktop.
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.)
<?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 );
}
}
};
@lnorton89
Copy link

This also strips the site name from the page title on the calendar pages but not the single events pages / the rest of the wordpress site.

@smutek
Copy link

smutek commented Jul 20, 2017

Suggest adding a check to make sure the Yoast plugin is active, first and foremost.

function tribe_remove_wpseo_title_rewrite() {

  // Bail if Yoast isn't active
  if(!defined('WPSEO_VERSION'))
    return null;
  
  // the other stuff....

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment