问题
I am trying to remove the Yoast WordPress SEO on a certain page because it is conflicting with another plugin.
I tried adding the code below to my functions.php but it does not seem to work, any help is appreciated.
Thank You
function remove_wpseo(){
if ( is_page(944)) {
global $wpseo_front;
remove_action( 'wp_head', array($wpseo_front, 'head'), 2 );
}
}
add_action('wp_enqueue_scripts','remove_wpseo');
回答1:
Enqueing is not the right moment to remove an action, use template_redirect
instead:
add_action('template_redirect','remove_wpseo');
function remove_wpseo(){
if ( is_page(944)) {
global $wpseo_front;
remove_action( 'wp_head', array($wpseo_front, 'head'), 2 ); // <-- check priority
}
}
Check the priority that the plugin uses to add the wp_head
action as the removal has to be the same and none if empty.
回答2:
Just in case someone still needs this. This worked for me. Change 'page' to 'post' if it's a blog post. Instead of trying to throw out Yoast completely, just hide the meta box.
add_action( 'add_meta_boxes', 'remove_post_meta_boxes', 11 );
function remove_post_meta_boxes() {
if( isset( $_GET['post'] ) && $_GET['post'] == '22' ) {
remove_meta_box( 'wpseo_meta', 'page', 'normal' );
}
}
来源:https://stackoverflow.com/questions/24391891/remove-yoast-wordpress-seo-on-a-page