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.
My Answer:
You can use the `WPSEO_Titles` class provided by the Yoast SEO plugin to get the decoded title from the Yoast settings. Here's an example code snippet to achieve this:
php
$catObj = get_term_by( 'slug', 'my_woo_category_slug', 'product_cat' );
$seoTitle = WPSEO_Titles::get_instance()->get_title( $catObj->term_id );
echo $seoTitle;
This code will retrieve the decoded title for the WooCommerce category specified by the slug 'my_woo_category_slug'. You can then use this title wherever you need to display it on your site.
Rate this post
4 of 5 based on 6092 votesComments