Code to use meta title in PHP markup?

#20999
  • Resolved Lou
    Rank Math free

    Hi,

    I would like to duplicate the meta title of any given page in the H1 tag of that same page, what PHP should I use to pull this in?

    I can only find hooks and filters, but all I need is something like <?php echo rank_math_meta_title(); ?> to put in my WordPress theme.

    I’m planning to use this mainly for archive/category pages

    Thanks

    • This topic was modified 5 years, 1 month ago by Lou.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can use the following snippet to display the title anywhere on your page template:

    
    $title = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_title" );
    echo RankMath\Helper::replace_vars( $title, $post );
    

    Looking forward to helping you. Thank you.

    ​​​​​​

    Lou
    Rank Math free

    Thanks for the code, but this appears to be displaying the meta title of the last known post, rather than the meta title of the category page being viewed.

    Hi there,

    Thanks for the response.

    I missed your last statement that you wanted to use this on category pages, the last snippet is designed to work on single posts.
    You can however use the following snippet for category pages:

    
     $term = get_queried_object();
     $title = RankMath\Helper::get_settings('titles.tax_' . $term->taxonomy .'_title');
     echo RankMath\Helper::replace_vars( $title, $post );
    

    I hope this info helps. Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Code to use meta title in PHP markup?’ is closed to new replies.