Last active
May 25, 2021 22:39
-
-
Save amboutwe/1c847f9c706ff6f8c9eca76abea23fb6 to your computer and use it in GitHub Desktop.
Remove Yoast from front end for a single post or page
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 | |
/********* 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 ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you only deactivate the Yoast's
Front_End_Integration
, it will still hide the title_tag and some other built-in wordpress filters (front-end-integration.php
, line207
and following:Use this snippet to completely disable YOAST in the frontend:
Tested with Yoast V. 15.7