Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove Yoast from front end for a single post or page
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Remove Yoast from front end for a single post or page
* Credit: Dodinas https://stackoverflow.com/questions/37845968/disable-wordpress-yoast-seo-on-single-page
* Last Tested: Nov 08 2019 using Yoast SEO 12.4 on WordPress 5.2.4
*********
* 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

ipaelo commented May 15, 2019

It works like a charm.

Thank you.

@timba64

This comment has been minimized.

Copy link

timba64 commented Oct 23, 2019

Thank you for gist! How did you make your profile picture? It`s cool!! 🥇

@amboutwe

This comment has been minimized.

Copy link
Owner Author

amboutwe commented Oct 23, 2019

@timba64 The avatar was created by my colleague. https://yoast.com/evolution-of-yoast-avatars/

@Tommy10Toes

This comment has been minimized.

Copy link

Tommy10Toes commented Nov 8, 2019

I can't seem to get this to work, But i'v got Yoast version 12.4 and WP version 5.2.4 - Any chance this this code needs to be tweaked?

@amboutwe

This comment has been minimized.

Copy link
Owner Author

amboutwe commented Nov 8, 2019

@Tommy10Toes I just tested the code and it removed the code output from the front end of the site.

@Tommy10Toes

This comment has been minimized.

Copy link

Tommy10Toes commented Nov 10, 2019

Very odd, This is what I have inside my functions.php file and I just can not get it to work. I have disabled WP Rocket just to be sure, but it does not make a difference.

`<?php
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
function enqueue_child_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}

add_action( 'template_redirect', 'remove_wpseo' );
function remove_wpseo() {
if ( is_page ( 1626 ) ) {
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 );
    }
}

}
`

@amboutwe

This comment has been minimized.

Copy link
Owner Author

amboutwe commented Nov 11, 2019

This is not the proper place to request support. Please check out our extensive Knowledge Base or visit the free support forum. If you require further support, upgrading to our premium version provides you with access to our support team.

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.