Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在特定的wordpress页面上使用noindex和nofollow_Wordpress_Code Snippets - Fatal编程技术网

如何在特定的wordpress页面上使用noindex和nofollow

如何在特定的wordpress页面上使用noindex和nofollow,wordpress,code-snippets,Wordpress,Code Snippets,我想阻止特定页面在一个片段中被wp索引。尝试了下面的方法,但元数据没有出现在标题中 add_action( 'wp_head', function() { if ($post->ID == 7407 || $post->ID == 7640 || $post->ID == 7660) { echo '<meta name="robots" content="noindex, nofollow">'; } } ); add_动作('wp

我想阻止特定页面在一个片段中被wp索引。尝试了下面的方法,但元数据没有出现在标题中

add_action( 'wp_head', function() {
   if ($post->ID == 7407 || $post->ID == 7640 || $post->ID == 7660) {
        echo '<meta name="robots" content="noindex, nofollow">';
    }
} );
add_动作('wp_head',函数(){
如果($post->ID==7407 | |$post->ID==7640 | |$post->ID==7660){
回声';
}
} );

有什么想法吗?

这里有一个可变范围的问题:
$post
对象在函数中不可用,除非您使用
全局
关键字

add_action( 'wp_head', function() {
   global $post;

   if ($post->ID == 7407 || $post->ID == 7640 || $post->ID == 7660) {
        echo '<meta name="robots" content="noindex, nofollow">';
    }
} );
add_action( 'wp_head', function() {
   if (is_page(7407) || is_page(7640) || is_page(7660)) {
        echo '<meta name="robots" content="noindex, nofollow">';
    }
} );