如何在 WordPress 中获取特定页面的文档 (seo) 标题

How to get document (seo) title of specific page in WordPress

我指的不是页面或 post 标题,而是 <title></title> 之间的标题。 so-called SEO 或文档标题。

我刚刚用谷歌搜索,但一无所获。我只知道获取当前页面的文档标题我们可以使用 wp_get_document_title()。但是如何通过其 post 或类别 ID 获取特定页面的文档标题?

好的,如果我们使用 Yoast,我们可以通过以下行获取文档标题:

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

您可以使用 get_the_title()the_title(),具体取决于您需要的上下文。不需要酵母。

详情在这里:

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

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