skip to Main Content

I don’t mean the page or post title but the title between <title> and </title>. The so-called SEO or document title.

I’ve just googled but found nothing. I only know to get document title of current page we can use wp_get_document_title(). But how to get document title of specific page by its post or category ID for example?

2

Answers


  1. Chosen as BEST ANSWER

    Ok, if we use Yoast we can get the document title by the following line:

    $seo_title = get_post_meta($post_id, '_yoast_wpseo_title', true);
    

  2. You can use get_the_title() or the_title(), depending in which context you need it. No Yoast needed.

    Details here:

    https://developer.wordpress.org/reference/functions/get_the_title/

    https://developer.wordpress.org/reference/functions/the_title/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search