4

我想手动获取 Yoast SEO 生成的数据,请参见下面的示例代码

此数据由 Yoast 生成并自动添加到head 标签中。

<!-- This site is optimized with the Yoast SEO plugin v4.2.1 - https://yoast.com/wordpress/plugins/seo/ -->
<meta name="description" content="bla bla bla"/>
<meta name="robots" content="noodp"/>
<link rel="canonical" href="http://example.localhost.com/" />
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="website" />
<meta property="og:title" content="bla bla bla" />
<meta property="og:url" content="http://example.localhost.com/" />
<meta property="og:site_name" content="Example.com" />
<meta property="og:image" content="http://example.com.au/wp-content/uploads/2016/11/example.png" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:description" content="bla bla bla." />
<meta name="twitter:title" content="bla bla bla" />
<meta name="twitter:image" content="http://example.com.au/wp-content/uploads/2016/11/example.png" />
<script type='application/ld+json'>{"@context":"http:\/\/schema.org","@type":"WebSite","@id":"#website","url":"http:\/\/example.localhost.com\/","name":"Example","potentialAction":{"@type":"SearchAction","target":"http:\/\/example.localhost.com\/?s={search_term_string}","query-input":"required name=search_term_string"}}</script>
<!-- / Yoast SEO plugin. -->

我不想使用wp_head(); 因为它还会生成其他脚本、样式以及您在 wordpress 网站中拥有的任何插件或代码。

我不需要所有这些代码。我只想获取 Yoast SEO 生成的代码,如上所示。有什么想法我该怎么做?

4

2 回答 2

4

您可以通过以下方式在任何页面中获取 yoast 元数据get_post_meta()

通过以下方式获取元值,

echo get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true); 
echo get_post_meta(get_the_ID(), '_yoast_wpseo_title', true); 

检查post_meta表格以获取与每个页面/帖子相关的所有值。

于 2017-05-30T06:39:20.273 回答
3

在下面使用这个:

do_action( 'wpseo_head' );

它将在您的脑海中打印所有 SEO 标题。无需通过帖子元添加。

于 2018-09-25T07:35:13.563 回答