Support » Plugin: Yoast SEO » how to get Yoast SEO Title of an Author on author.php and single.php

  • Resolved nehagrover027

    (@nehagrover027)


    Hi there,

    How can I get value of Yoast SEO title for a particular author on author.php and single.php.?
    I’ve tried many functions like get_the_author_meta( ‘_yoast_wpseo_title’, $post->post_author );
    and
    get_post_meta( $author_id, ‘_yoast_wpseo_title’, true);
    but none of them is working. Can you please suggest what I’m missing here.?

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Saša

    (@stodorovic)

    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.

    Thread Starter nehagrover027

    (@nehagrover027)

    Hi Saša,

    Can you please redirect me to the exact function. I’m lost here.!

    Saša

    (@stodorovic)

    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.

    Thread Starter nehagrover027

    (@nehagrover027)

    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/

    Saša

    (@stodorovic)

    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.

    Saša

    (@stodorovic)

    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.

    Thread Starter nehagrover027

    (@nehagrover027)

    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.?

    Saša

    (@stodorovic)

    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.

    Thread Starter nehagrover027

    (@nehagrover027)

    Thank you so much.! that worked perfectly.!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘how to get Yoast SEO Title of an Author on author.php and single.php’ is closed to new replies.