Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Yoast SEO title snippets
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Remove Yoast SEO Title From All Pages
* Credit: Yoast Team
* Last Tested: Aug 11 2017 using Yoast SEO 5.2 on WordPress 4.8.1
*/
add_filter( 'wpseo_title', '__return_false' );
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Remove Yoast SEO Title From An Individual Post/Page/CPT
* Credit: Yoast Team
* Last Tested: Aug 11 2017 using Yoast SEO 5.2 on WordPress 4.8.1
*********
* 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, 1234567, 12345678 ) )
* Multiple of different types can repeat the if statement
*/
add_filter( 'wpseo_title', 'remove_one_wpseo_title' );
function remove_one_wpseo_title() {
if ( is_single ( 123456 ) ) {
return false;
}
/* Use a second if statement here when needed */
}
@Marco-Luongo

This comment has been minimized.

Copy link

commented Mar 20, 2018

Hi there, i'm facing problem when try to read Yoast var inside category template.
If i try to print the title with wp_title(), i get the correct snippet rewrite from yoast, but i'm not able to read description.
I did
get_term_meta($category->id, '_yoast_wpseo_title' ,true);
get_term_meta($category->id, '_yoast_wpseo_metadesc' ,true);
always return empty values. My question is how to read title and desc snippet by code side?

@PBhupalSingh

This comment has been minimized.

Copy link

commented Sep 1, 2019

You could use:
get_post_meta($post->ID, '_yoast_wpseo_metadesc' ,true);

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.