问题描述
我的意思不是页面或帖子标题,而是<title>
和</title>
之间的标题。所谓的SEO或文档标题。
我刚刚用Google搜索,但什么也没找到。我只知道要获取当前页面的文档标题,我们可以使用wp_get_document_title()
。但是,例如,如何通过其帖子或类别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/