我想添加blogposting模式标记,以便为丰富的数据自动优化每个新帖子。网络上的一些代码是杂乱无章的,每个帖子都需要更新,而且插件也不是最好的选择,因为这是自定义主题,我们正试图将插件需求降到最低。是否有一个代码,我可以添加到single.php文件,以便每个页面都有适当的结构化数据,没有插件,或在管理或每个帖子额外的变化。谢谢!
发布于 2019-04-17 21:23:21
我认为你想去的路线是用JSON-LD。
来自CSS的这是一个很好的指南来指导你如何去做。
概述:
指南中的例子:
add_action('wp_head', function() {
$schema = array(
// Tell search engines that this is structured data
'@context' => "http://schema.org",
// Tell search engines the content type it is looking at
'@type' => get_field('schema_type', 'options'),
// Provide search engines with the site name and address
'name' => get_bloginfo('name'),
'url' => get_home_url(),
// Provide the company address
'telephone' => '+49' . get_field('company_phone', 'options'), //needs country code
'address' => array(
'@type' => 'PostalAddress',
'streetAddress' => get_field('address_street', 'option'),
'postalCode' => get_field('address_postal', 'option'),
'addressLocality' => get_field('address_locality', 'option'),
'addressRegion' => get_field('address_region', 'option'),
'addressCountry' => get_field('address_country', 'option')
)
);
}指南中的例子:
echo '' . json_encode($schema) . '';这是我找到的最好的方法,因为您可以在模板中使用wordpress中的所有可用内容,包括ACF,并且可以添加条件在特定页面上运行脚本。
https://wordpress.stackexchange.com/questions/334635
复制相似问题