Last active
November 22, 2023 12:13
-
-
Save kasparsd/5574458 to your computer and use it in GitHub Desktop.
Disable page title rewrite feature in WordPress SEO plugin
This file contains 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 | |
// 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; | |
} |
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
In the latest Yoast SEO version, you'll need to use the following to remove the
wp_title
filter: