<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

function haup_add_noindex_to_taxonomy() {
	$content = '<meta name="robots" content="noindex, follow" />';

	$output = ''; // 初期化


	//タグアーカイブを除外
	if( isset( GetOP01_optimize()['add-noindex-tag-for-tag'] ) && GetOP01_optimize()['add-noindex-tag-for-tag'] ==1){
		if( is_tag() ){
			$output = $content . "\n";
		}
	}

	//カテゴリーアーカイブを除外
	if( isset( GetOP01_optimize()['add-noindex-tag-for-category'] ) && GetOP01_optimize()['add-noindex-tag-for-category'] ==1){
		if( is_category() ){
			$output = $content . "\n";
		}
	}

	//カスタムタクソノミーアーカイブを除外
	if( isset( GetOP01_optimize()['add-noindex-tag-for-taxonomy'] ) && GetOP01_optimize()['add-noindex-tag-for-taxonomy'] ==1){
		if( is_tax() ){
			$output = $content . "\n";
		}
	}

	//作者アーカイブを除外
	if( isset( GetOP01_optimize()['add-noindex-tag-for-author'] ) && GetOP01_optimize()['add-noindex-tag-for-author'] ==1){
		if( is_author() ){
			$output = $content . "\n";
		}
	}

	//日付アーカイブの処理
	if( isset( GetOP01_optimize()['add-noindex-tag-for-date'] ) && GetOP01_optimize()['add-noindex-tag-for-date'] ==1){
		if (is_archive() && (is_month() || is_year() || is_day())) {
			$output = $content . "\n";
		}
	}

	//検索結果の処理
	if( isset( GetOP01_optimize()['add-noindex-tag-for-search'] ) && GetOP01_optimize()['add-noindex-tag-for-search'] ==1){
		if (is_search()) {
		$output = $content . "\n";
		}
	}

	//カスタム投稿タイプアーカイブの処理
	if( isset( GetOP01_optimize()['add-noindex-tag-for-cpt'] ) && GetOP01_optimize()['add-noindex-tag-for-cpt'] ==1){
		if (is_post_type_archive()) {
			$output = $content . "\n";
		}
	}

	//404エラーページの処理
	if( isset( GetOP01_optimize()['add-noindex-tag-for-404'] ) && GetOP01_optimize()['add-noindex-tag-for-404'] ==1){
		if (is_404()) {
			$output = $content . "\n";
		}
	}

	//メディアアーカイブの処理
	if( isset( GetOP01_optimize()['add-noindex-tag-for-media'] ) && GetOP01_optimize()['add-noindex-tag-for-media'] ==1){
		if (is_attachment()) {
			$output = $content . "\n";
		}
	}

	echo wp_kses_post( $output );
}
add_action('wp_head', 'haup_add_noindex_to_taxonomy',1 );