Wordpress > Yoast > 如何调整或禁用评论 URL 的元机器人?

问题描述

如果有人能启发我在 Yoast 中使用元机器人作为评论网址,那就太好了。

正如您在这些示例 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 元机器人?

在网上冲浪时,我发现了一个可以帮助我解决后者的代码片段:

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)”更改为不同的标识符,其中包括所有评论网址,仅此而已。

期待任何有价值的提示

保持阳性和测试阴性, 罗马

解决方法


编辑

我没有太多事情要做。

我认为您正在寻找 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 的页面,这些页面有打开的评论并且至少有 1 条评论,其他任何内容都将被编入索引。

如果您不关心将任何大于 0 的页面编入索引,则只需删除 comments_open( get_the_ID() ) && have_comments()

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

User-agent: *
Disallow: /page/

Tho,我想我最近读到 Google 机器人将应用机器人元标记规则而不是 robot.txt 文件(如果两者都存在)。我想可以涉足一些东西。

,

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

棘手的是,您仍然希望将第 0 页编入索引。

完全正确。

已打开评论且至少有 1 条评论

这里的“评论打开”是什么意思?

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

如果我在意,alias 不想将这些页面编入索引,我只需要保留您的代码片段原样,对吗?

,

当我添加您的代码片段时,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','__return_false' );
};
?>