You should get instance of class WPSEO_Frontend and invoke method title. It should return title which is shown on current page.
In next weeks, Yoast SEO will release new version which will change a lot of the code. New version will have different access to “title” (but I think that you could use older method for some time).
If you need to “generate” titles for particular posts on archive page then you should use different way.
Hi Saša,
Can you please redirect me to the exact function. I’m lost here.!
I’ll try to help, but I’m not sure that I understood correctly question. An example:
if ( class_exists('WPSEO_Frontend') ) {
$yoast_current_title = WPSEO_Frontend::get_instance()->title( '' );
}
I’m writing it “on the fly” without testing in real site.
Actually I managed to show it on author.php using the function wp_title() but the main issue is with single.php
On Single posts pages, I’m trying to show Author info, like his name, description, title (Yoast SEO Title), social media links etc.
Everything else is working fine, except this Yoast SEO title. Can you please help me figuring this out.
for example here: http://bigtincanstg.wpengine.com/blog/branding-and-sales-enablement-whats-the-connection/
It seems that you want something as https://github.com/Yoast/wordpress-seo/issues/13086
Probably you need to use “author title template” to get “author title” in “single.php”. I’ll try to make some example soon.
If I understood correctly then you need following code:
$yst_title_author_opt = WPSEO_Options::get( 'title-author-wpseo' );
$yst_title_author = wpseo_replace_vars( $yst_title_author_opt, array() );
To prevent fatal errors, then please add code which check existence of this method/function (eg. function_exists( 'wpseo_replace_vars' )
). In opposite case, deactivation of Yoast SEO could produce PHP fatal errors.
Nop, That’s showing the variables set for Author Archives title, whereas I need custom title set for that particular author with its Id or something.
Its showing this title: https://www.screencast.com/t/Kf0Kt4v3
whereas I need this: https://www.screencast.com/t/Ghydd1SQQVTV
Please let me know if I’m making sense and is it even possible.?
You can simplify code because you can use WP function get_user_meta. When I’ve re-read your initial comment then I’ve figured out that you have used wrong function. Correct code is get_user_meta( $author_id, 'wpseo_title', true );
. If you don’t need fallback to Yoast template, then you don’t need previous code.
Thank you so much.! that worked perfectly.!