Skip to content

Instantly share code, notes, and snippets.

@amboutwe
Last active February 17, 2022 14:57
Show Gist options
  • Save amboutwe/34b80a4755b1a9140026bc2c82720114 to your computer and use it in GitHub Desktop.
Save amboutwe/34b80a4755b1a9140026bc2c82720114 to your computer and use it in GitHub Desktop.
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: Jun 17 2020 using Yoast SEO 14.3 on WordPress 5.4.2
*/
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: Jun 17 2020 using Yoast SEO 14.3 on WordPress 5.4.2
*********
* 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( $title ) {
if ( is_single ( 123456 ) ) {
return false;
}
/* Use a second if statement here when needed */
return $title; /* Do not remove this line */
}
@c0derman
Copy link

c0derman commented Dec 6, 2020

You can also check if is_tag() post type. This example capitalizes the title.

add_filter( 'wpseo_title', 'uppercase_seo_title' );
function uppercase_seo_title( $title ) {
	if ( is_tax() ) {
		return ucwords( $title );
	}
	return $title;
}

hello @roadsunknown

i have same problem

it always back empty value with custom post type

work on pages and posts but not custom post type

in page retern the value good

the code
<meta property="og:description" content="<?php echo get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true); ?>"/>
and i got

<meta property="og:description" content="the decs from page"/> 
and in

custom post type

it back like that

<meta property="og:description" content=""/> 

im not sure why

the post type this

function work_type() { $labels = array( 'name' => _x('اقسام الاعمال', 'taxonomy general name'), 'singular_name' => _x('قسم', 'taxonomy singular name'), 'search_items' => __('البحث فى اقسام الاعمال'), 'all_items' => __('جميع اقسام الاعمال'), 'edit_item' => __('تحرير قسم'), 'update_item' => __('تحديث قسم'), 'add_new_item' => __('اضف قسم جديد'), 'new_item_name' => __('قسم جديد'), 'menu_name' => __('اقسام الاعمال'), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); register_taxonomy('work_type', 'works', $args); } add_action('init', 'work_type', 0);

@nafeeees
Copy link

nafeeees commented Oct 1, 2021

Hi,

I want to remove the meta title and description from the review page.
I have created a separate page for my reviews section but the parent page and reviews page meta title and description is show same

Example
Parent page - joint-n-11-review.html
Reviews Page - joint-n-11-review.html/reviews

Thank You

@amboutwe
Copy link
Author

amboutwe commented Oct 1, 2021

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.

@Dubidubiduu
Copy link

Needed to change in line 22 from is_single to is_page but then it worked like a charm for me. Searched the whole web and a longer time to fix this issue with wordpress, yoast and salient theme.

Big, big thanks amboutwe!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment