<?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 | |
* Note: For version 14+, please use the code here: https://developer.yoast.com/customization/yoast-seo/disabling-yoast-seo | |
********* | |
* 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 ); | |
} | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
Thank you for gist! How did you make your profile picture? It`s cool!! |
This comment has been minimized.
This comment has been minimized.
@timba64 The avatar was created by my colleague. https://yoast.com/evolution-of-yoast-avatars/ |
This comment has been minimized.
This comment has been minimized.
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? |
This comment has been minimized.
This comment has been minimized.
@Tommy10Toes I just tested the code and it removed the code output from the front end of the site. |
This comment has been minimized.
This comment has been minimized.
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( 'template_redirect', 'remove_wpseo' );
} |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
Seems like this doesn't work completely. Sometimes the template_redirect hook is not being called. I have one page that I'm serving with dynamic content. You can select filters there, that will narrow down the dynamic content. But as soon as I do this, Yoast is inserting the meta tags on the frontend again. The page get's refreshed and a different url, but the page id remains the same. I'll investigate it a bit more and see if I can figure it out. But if you have any suggestions I would love to hear them. I still think this is something that should be a setting within the plugin. Especially for a mix of wp pages and dynamic pages. (E.g. content loaded through a JS API). |
This comment has been minimized.
This comment has been minimized.
Is not working for me, maybe there is any update of this code? |
This comment has been minimized.
This comment has been minimized.
@fabianrod This is not the proper place to request support. Please check out our extensive help section or visit the free support forum. If you require further support, upgrading to our premium version provides you with access to our support team. |
This comment has been minimized.
This comment has been minimized.
This GIST solution will not work with Yoast version 14 and above. You now need to use.
|
This comment has been minimized.
This comment has been minimized.
Thanks @APlusDesign. That worked perfectly |
This comment has been minimized.
It works like a charm.
Thank you.