【问题标题】:How to Add "itemReviewed" in WP-postratings plugin如何在 WP-postratings 插件中添加“itemReviewed”
【发布时间】:2020-12-18 20:37:09
【问题描述】:

我想在网站上设置评论标记,该标记将在 sn-p 搜索引擎中显示星星和评论的作者。

CMS 网站:WordPress 5.3 - Astra 主题 我使用插件:WP-Postrating (https://wordpress.org/plugins/wp-postratings/)

1.使用插件说明中描述的过滤器更改了function.php中的标记类型:

 add_filter( 'wp_postratings_schema_itemtype', 'wp_postratings_schema_itemtype' );  
    function wp_postratings_schema_itemtype( $itemtype ) {  
        return 'itemscope itemtype';  
    }  

标记现在定义为评论link

但是因为报错:需要为itemReviewed字段指定值。

搜索系统的sn-p中不显示星星和作者。

请给我们一个提示。我应该在function.php 添加什么代码来添加这个字段?以及您希望在该字段中看到什么,例如一篇文章的标题或手动填写itemReviewed。也许您需要在文章编辑器中添加一些特殊字段。

我将不胜感激。雇主想做这个,我是新手开发者https://improvecraft.com/

【问题讨论】:

    标签: wordpress schema google-rich-snippets


    【解决方案1】:

    这是一个老问题,您可能想出了如何添加此代码。如果有人仍然需要它,这段代码应该可以工作(您也可以更改 itemtype):

    add_filter( 'wp_postratings_schema_itemtype','wp_postratings_schema_itemtype');
    function wp_postratings_schema_itemtype($itemtype) {
    
        global $post;
    
        $title = get_the_title($post->ID);
    
        return 'itemscope itemReviewed="' . $title . '" itemtype="http://schema.org/LocalBusiness"';
    }
    

    【讨论】:

    • 没有等待答案,将网站上的模板更改为 GeneratePress =) 不过还是谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 2021-01-11
    • 1970-01-01
    相关资源
    最近更新 更多