Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Last active November 22, 2023 12:13
Show Gist options
  • Save kasparsd/5574458 to your computer and use it in GitHub Desktop.
Save kasparsd/5574458 to your computer and use it in GitHub Desktop.
Disable page title rewrite feature in WordPress SEO plugin
<?php
// Remove the wp_title filter
add_action( 'init', 'remove_wpseo_title_rewrite' );
function maybe_remove_wpseo_title_rewrite() {
global $wpseo_front;
remove_filter( 'wp_title', array( $wpseo_front, 'title' ), 15 );
}
// Remove the title metabox from backend UI
add_filter( 'init', 'remove_wpseo_title_rewrite_metabox' );
function remove_wpseo_title_rewrite_metabox( $metaboxes ) {
if ( isset( $metaboxes['title'] ) )
unset( $metaboxes['title'] )
return $metaboxes;
}
@mmikhan
Copy link

mmikhan commented Jan 1, 2018

In the latest Yoast SEO version, you'll need to use the following to remove the wp_title filter:

// Remove the wp_title filter
 add_action( 'init', 'remove_wpseo_title_rewrite' );
 function remove_wpseo_title_rewrite () {
    $wpseo_front = WPSEO_Frontend::get_instance();

    remove_filter( 'pre_get_document_title', array( $wpseo_front, 'title' ), 15 );
    remove_filter( 'wp_title', array( $wpseo_front, 'title' ), 15 );
}

@aldemarcalazans
Copy link

An improvement of iamazik code, which avoids a PHP error when YOAST plugin is disabled:

// Remove the wp_title filter
if ( class_exists('WPSEO_Frontend') ) {
	 add_action( 'init', 'remove_wpseo_title_rewrite' );
	 function remove_wpseo_title_rewrite () {
		$wpseo_front = WPSEO_Frontend::get_instance();

		remove_filter( 'pre_get_document_title', array( $wpseo_front, 'title' ), 15 );
		remove_filter( 'wp_title', array( $wpseo_front, 'title' ), 15 );
	}
}

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