我想手动获取Yoast SEO生成的数据,请参阅下面的示例代码
此数据由Yoast生成,并自动将其添加到 head tag 中 .
<!-- 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生成代码 . 任何想法我怎么能这样做?
2 回答
您可以通过
get_post_meta()
获取任何页面中的yoast元数据,通过以下方式获取元值,
检查
post_meta
表以获取与每个页面/帖子相关的所有值 .使用以下内容:
它会打印出你头脑中的所有SEO Headers . 无需通过post meta添加 .