【问题标题】:Wordpress > Yoast > How to adjust (or disable) Meta-Robots for Comment-URLs?Wordpress > Yoast > 如何调整(或禁用)评论 URL 的元机器人?
【发布时间】:2021-06-09 09:30:06
【问题描述】:

如果有人能告诉我有关在 Yoast 中使用元机器人作为评论 URL 的知识,那就太好了。

您可以在这些示例 URL 的源代码中看到:

https://www.bussgeldkatalog.org/geschwindigkeitsueberschreitung/comment-page-2/ https://www.bussgeldkatalog.org/geschwindigkeitsueberschreitung/comment-page-3/

播放了两个相互矛盾的元机器人命令。第一个说“noindex”,而来自 Yoast 的第二个说“index”。这些评论 URL 应该有一个唯一的元机器人标签,上面写着“noindex,follow”。

我怎样才能让 Yoast 将其“索引,关注”元机器人标签变成“无索引,关注”标签,或者更好的是,仅在评论 URL 上完全禁用 Yoast 元机器人?

在网上冲浪我发现了一个可以帮助我处理后者的代码-sn-p:

add_filter( ‘wpseo_robots’, ‘yoast_seo_robots_remove_single’ );

function yoast_seo_robots_remove_single( $robots ) {
if ( is_single ( 123456 ) ) {
return false;
} else {
return $robots;}
}

问题是我不知道如何将“is_single (123456)”更改为不同的标识符,其中包括所有评论 URL,仅此而已。

期待任何有价值的提示!

保持积极和测试阴性, 罗马

【问题讨论】:

    标签: wordpress meta-tags yoast


    【解决方案1】:

    编辑

    我没有太多事情要做。

    我想你正在寻找is_paged()。

    确定查询是否针对分页结果而不是针对第一页。

    <?php
    add_action( 'init', 'wp_so66581686_wpseo_robots' );
    function wp_so66581686_wpseo_robots() {
    
        /**
        * Determines whether the current request is for an administrative interface page.
        * Determines whether the query is for a paged result and not for the first page.
        * Determines whether the current post is open for comments.
        * Determines whether current WordPress query has comments to loop over.
        */
        if ( ! is_admin() && is_paged() && comments_open( get_the_ID() ) && have_comments() )
            add_filter( 'wpseo_robots', '__return_false' );
    };
    ?>
    

    我添加了一些冗余,因为您不希望其他页面发生任何事情。棘手的是,您仍然希望您的第一页(即第 0 页)被编入索引。

    这里我们不索引 > 0、打开 cmets 且至少有 1 个 cmets 的页面,其他任何内容都将被索引。

    如果您不关心索引任何 > 0 的页面,那么只需删除 comments_open( get_the_ID() ) &amp;&amp; have_comments()。

    另一种方法是将您的 robot.txt 文件更新为:

    User-agent: *
    Disallow: /page/
    

    我想我最近读到,如果两者都存在,Google 机器人将应用机器人元标记规则而不是 robot.txt 文件。我想可以尝试一下。

    【讨论】:

    • 如果您没有从我的回答中收到@amarinediary 的通知,请查看上方/下方:)
    • 我已经在我的问题正文中提到了类似的方法。如果我要添加 add_filter( 'wpseo_robots', '__return_false' );到主题的function.php,它将影响所有页面,这将搞砸整个网站。如何让 add_filter( 'wpseo_robots', '__return_false' ) 只在分页的 cmets 页面上触发?
    • 哦,好的,我明白了,只是澄清一下,paginated comments page 是什么意思。您是否有显示所有 cmets 的特定页面或帖子?还是您的意思是页面和帖子至少有 1 cmets ?试着在这一点上更精确一点
    • 这些页面是通过设置 -> 讨论 -> 其他评论设置 -> 将 cmets 分成页面,每页 XXXX 顶级 cmets,默认显示第一页/最后一页。它们不是自定义帖子类型,而是通过标准 WP 功能生成的 WP 页面(无插件、无第三方或自定义代码)。
    • 我将您的代码 sn-p 添加到 functions.php,通过 wp-rocket 删除缓存,在 chrome 隐身模式中打开 bussgeldkatalog.org/geschwindigkeitsueberschreitung/…,并且 仍然存在:/ ...知道为什么它不起作用吗?
    【解决方案2】:

    哦,哇,这看起来是一个非常可行的解决方案!我对此感到很兴奋。您能否就您提出的解决方案给我一些最后的澄清?

    棘手的是你仍然希望你的第一页,第 0 页,被索引。

    完全正确。

    已打开 cmets 且至少有 1 个 cmets

    这里的“cmets open”是什么意思?

    如果您不关心索引任何页面 > 0

    如果我在乎,alias 不希望这些页面被索引,我只需要保留您的代码 sn-p 原样,对吗?

    【讨论】:

      【解决方案3】:

      这就是我添加代码 sn-p 时 functions.php 的外观:

      <?php
      
      // Exit if accessed directly
      if ( !defined('ABSPATH')) exit;
      
      //setlocale(LC_ALL, 'de_DE');
      date_default_timezone_set('Europe/Berlin');
      
      require_once('includes/init.php');
      require_once('includes/comments.php');
      require_once('includes/shortcodes.php');
      require_once('includes/breadcrumb.php');
      require_once('includes/ads.php');
      require_once('includes/ratings.php');
      require_once('includes/pagination.php');
      
      add_action( 'init', 'wp_so66581686_wpseo_robots' );
      function wp_so66581686_wpseo_robots() {
      
          /**
          * Determines whether the current request is for an administrative interface page.
          * Determines whether the query is for a paged result and not for the first page.
          * Determines whether the current post is open for comments.
          * Determines whether current WordPress query has comments to loop over.
          */
          if ( ! is_admin() && is_paged() && comments_open( get_the_ID() ) && have_comments() )
              add_filter( 'wpseo_robots', '__return_false' );
      };
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多