• 解決済 ForestRiver

    (@forestriver)


    meta name=”robots” content=”” を変更したいのですがうまくいきません。
    追加するだけならできそうなのですが、

    if ( ! function_exists( 'my_noRobots' ) ) :
    	add_action( 'wp_head', 'my_noRobots' ,10,1);
    	function my_noRobots($meta_robots_index) {
    	    if( is_home()||is_front_page() ){
    	    	$tanbo_meta_robots_index = $meta_robots_index;
    	    }else if( is_search()||is_category()||is_tag()||is_404()||is_archive()){
    	    	$tanbo_meta_robots_index = preg_replace('/<meta[^>]+name="robots".+.>/','<meta name="robots" content="noindex,nofollow" />', $meta_robots_index);
    	    }else{
    	    	$tanbo_meta_robots_index = preg_replace('/<meta[^>]+name="robots".+.>/','<meta name="robots" content="noindex,follows" />', $meta_robots_index);
    	    }
    	    return $tanbo_meta_robots_index;
    	}
    endif;

    でちゃんと動いているか確かめたいのです。
    フックの仕方が悪いのでしょうか?

    ご指導のほどよろしくお願いいたします。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • こんにちは、

    アクションの場合は、return ではなく echo 等を使います。

    ソースを書くときは、シングルクウォートではなく、逆クウォートで書きましょう

    こんな感じでどうですか?

    if ( ! function_exists( 'my_noRobots' ) ) {
    	add_action( 'wp_head', 'my_noRobots' ,10);
    
    	function my_noRobots() {
    
    		if( is_home()||is_front_page() ){
    
    		}else if( is_search()||is_category()||is_tag()||is_404()||is_archive()){
    			wp_no_robots();
    		}else{
    			wp_no_robots();
    		}
    
    	}
    }
    トピック投稿者 ForestRiver

    (@forestriver)

    nobitaさん
    いつもご返答ありがとうございます。

    何とか解決できそうです。

    ありがとうございます。

    逆クウォート注意します

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「meta name="robots" content="" を変更したい」には新たに返信することはできません。