Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove Yoast from front and back end for a single post or page
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Remove Yoast from front and back end for a single post or page
* Credit: Dodinas https://stackoverflow.com/questions/37845968/disable-wordpress-yoast-seo-on-single-page
* Last Tested: Jul 13 2018 using Yoast SEO 7.8 on WordPress 4.9.7
*********
* DIFFERENT POST TYPES
* Post: Change 123456 to the post ID
* Page: Change is_single to is_page and 123456 to the page ID
* Custom Post Type: Change is_single to is_singular and 123456 to the 'post_type_slug'
Example: is_singular( 'cpt_slug' )
*********
* MULTIPLE ITEMS
* Multiple of the same type can use an array.
Example: is_single( array( 123456, 234567, 345678 ) )
* Multiple of different types can repeat the if statement
*/
add_action( 'template_redirect', 'remove_wpseo' );
function remove_wpseo() {
if ( is_single ( 123456 ) ) {
global $wpseo_front;
if ( defined( $wpseo_front ) ) {
remove_action( 'wp_head', array ($wpseo_front, 'head' ), 1 );
} else {
$wp_thing = WPSEO_Frontend::get_instance();
remove_action( 'wp_head', array( $wp_thing, 'head' ), 1 );
}
}
}
@ipaelo

This comment has been minimized.

Copy link

commented May 15, 2019

It works like a charm.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.