WordPress >酸奶>如何调整(或禁用)评论 URL 的元机器人? [英] Wordpress > Yoast > How to adjust (or disable) Meta-Robots for Comment-URLs?
问题描述
如果有人能启发我在 Yoast 中使用元机器人作为评论网址,那就太好了.
It would be wonderful if someone could enlighten me about the use of meta-robots for comment-urls in Yoast.
正如您在这些示例 URL 的源代码中所见:
As you can see in the source code of these example URL:
https://www.bussgeldkatalog.org/geschwindigkeitsueberschreitung/comment-page-2/https://www.bussgeldkatalog.org/geschwindigkeitsueberschreitung/comment-page-3/
执行了两个相互矛盾的元机器人命令.第一个表示noindex",而 Yoast 的第二个表示index".这些评论网址应该有一个独特的元机器人标签,上面写着noindex,follow".
two contradicting meta-robots commands are played out. The first one says "noindex", whereas the second one from Yoast says "index". There should be one unique meta-robots tag for these comment URLs saying "noindex, follow".
我怎样才能让 Yoast 将其索引,关注"元机器人标签转换为无索引,关注"标签,或者更好的是,仅在评论 URL 上完全禁用 Yoast 元机器人?
How can I possibly make Yoast either turn its "index, follow" meta-robots tag into a "noindex, follow" one or, even better, completely disable Yoast meta-robots only on comment URLs?
在网上冲浪时,我发现了一个可以帮助我解决后者的代码片段:
Surfing on the web I found a code-snippet that could help me with the latter:
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)"更改为不同的标识符,其中包括所有评论网址,仅此而已.
The problem is that I have no idea how to change "is_single ( 123456 )" into a different identifier, which includes all the comment URLs, and nothing else.
期待任何有价值的提示!
Looking forward for any valuable hints!
保持积极的态度&测试阴性,罗马
Stay positive & test negative, Roman
推荐答案
当我添加您的代码片段时,functions.php 是这样的:
This is how functions.php look when I add your code snippet:
<?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' );
};
?>
这篇关于WordPress >酸奶>如何调整(或禁用)评论 URL 的元机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!