Wordpress - Display Yoast WordPress SEO title in archive template
Get Archive SEO titles
If you defined a Custom Post Type archive title you can get that by:
$titles = get_option( 'wpseo_titles' );
$title = $titles['title-ptarchive-POST_TYPE'];
echo apply_filters( 'the_title', $title );
Remember to replace POST_TYPE
by your own Custom Post Type.
To display all the wpseo_title
variables, you can use:
printf( '<pre>%s</pre>', print_r( get_option( 'wpseo_titles' ), 1 ) );
So you can easily pick the one you need.
Get Term SEO titles
Categories
By using this code you can get the SEO title you defined:
$cat_id = get_query_var( 'cat' );
$meta = get_option( 'wpseo_taxonomy_meta' );
$title = $meta['category'][$cat_id]['wpseo_title'];
echo apply_filters( 'the_title', $title );
Tags
By using this code you can get the SEO title you defined:
$tag_id = get_query_var( 'tag' );
$meta = get_option( 'wpseo_taxonomy_meta' );
$title = $meta['post_tag'][$tag_id]['wpseo_title'];
echo apply_filters( 'the_title', $title );
To display all wpseo_taxonomy_meta
variables, you can use:
printf( '<pre>%s</pre>', print_r( get_option( 'wpseo_taxonomy_meta' ), 1 ) );
This way you can see the structure and available variables.
On archive page in post loop add following line of code to make it work
echo get_post_meta(get_the_ID(), '_yoast_wpseo_title', true);
Tell me whether it is working for you or i will provide another solution.