Home > OS >  Get decoded title from Yoast SEO
Get decoded title from Yoast SEO

Time:09-19

Inside the Yoast settings, there are tags such as: Term Title, Page, Sitename etc. And you can add them to title fields inside castom terms. For example I want to get Woocommerce category Yoast title:

$catObj     = get_term_by( 'slug', 'my_woo_category_slug', 'product_cat' );
$seoTitle   = WPSEO_Taxonomy_Meta::get_term_meta( $catObj, 'product_cat', 'title' );

But with my code I get string like: %%term_title%% %%page%% %%sep%% %%sitename%% Is there any functions or tricks to get this string decoded from this tags? Just like this SEO plugin displays the title on any post page out of the box.

CodePudding user response:

@CBroe in the comment helped me find the solution. Working code for my issue:

$catObj     = get_term_by( 'slug', 'my_woo_category_slug', 'product_cat' );
$seoTitle   = WPSEO_Taxonomy_Meta::get_term_meta( $catObj, 'product_cat', 'title' );
$cleanTitle = '';
$cleanTitle = wpseo_replace_vars( $seoTitle, $catObj );
  • Related