我一直在使用我的WordPress网站创建各种类型的内容,我显然提交我的网站地图到谷歌,以使我的网站索引。但有一些内容,我不想在谷歌,因此不希望它也在网站地图。
我以前使用插件来实现它,但是现在我们有了重叠的功能,因为WordPress现在支持sitemaps。
那么,我如何才能完全删除WordPress站点地图,从而只使用插件,Google搜索控制台就不能读取我的wp-sitemap.xml,或者有选择地删除WordPress站点地图中的一些帖子,这样我就可以根据自己的口味定制站点地图,然后删除站点地图插件。
发布于 2020-09-01 13:02:24
禁用站点地图很容易,只需将这一行添加到您的functions.php中:
add_filter( 'wp_sitemaps_enabled', '__return_false' );删除特定职位如下:
add_filter(
'wp_sitemaps_posts_query_args',
function( $args, $post_type ) {
if ( 'post' !== $post_type ) {
return $args;
}
$args['post__not_in'] = isset( $args['post__not_in'] ) ? $args['post__not_in'] : array();
$args['post__not_in'][] = 123; // 123 is the ID of the post to exclude.
return $args;
},
10,
2
);如果你宁愿使用WP本地方式而不是插件,那么自定义站点地图有很多种方法。
https://wordpress.stackexchange.com/questions/374098
复制相似问题