概要
tec_events_seo_robots_meta_content
フィルタは、The Events Calendar プラグインによって提供されるイベントページのSEOに関連するメタコンテンツを制御するためのハンドルです。このフィルタは、特定のイベントページにおける「robots」メタタグの内容を変更する際に使用されます。主に次のような機能を実装する際に役立ちます。
- 特定のイベントページのインデックスの制御
- サーチエンジンへのクロール指示のカスタマイズ
- パフォーマンス改善のためのSEO調整
- プライバシー保護のためのロボットフォローメタ設定
- 特定の条件に基づくメタデータ属性の追加
- ユーザータイプやページ特性に応じたSEO設定の変更
フィルタの概要
-
構文:
add_filter('tec_events_seo_robots_meta_content', 'your_custom_function');
-
パラメータ:
$robots_meta_content
: 既定のrobotsメタコンテンツ(文字列)。
-
戻り値:
- 変更後のrobotsメタコンテンツ(文字列)。
-
使用可能なプラグイン: The Events Calendar
- 使用可能なバージョン: 5.0以降
- 対応ワードプレスのバージョン: 5.0以降
サンプルコード
サンプルコード1: 全てのイベントページをインデックス禁止にする
add_filter('tec_events_seo_robots_meta_content', function($robots_meta_content) {
return 'noindex, nofollow';
});
このコードは、すべてのイベントページに対して検索エンジンのインデックスを禁止します。
サンプルコード2: 特定の条件に基づいて設定を変更する
add_filter('tec_events_seo_robots_meta_content', function($robots_meta_content) {
if (is_single() && in_the_loop()) {
return 'noindex';
}
return $robots_meta_content;
});
このコードは、個別のイベントページのみを「noindex」に設定しますが、他のページは元の設定を維持します。
サンプルコード3: キーワードに基づくメタタグの追加
add_filter('tec_events_seo_robots_meta_content', function($robots_meta_content) {
if (has_tag('特定のキーワード')) {
return 'index, follow';
}
return $robots_meta_content;
});
このコードは、特定のキーワードが付けられたイベントページについて、インデックスされるように設定します。
サンプルコード4: ロボットメタのカスタマイズ
add_filter('tec_events_seo_robots_meta_content', function($robots_meta_content) {
return 'max-snippet:-1, max-image-preview:large';
});
このコードは、検索エンジンに対して特定のスニペットの扱いや画像プレビューのサイズの設定を指示します。
サンプルコード5: ゲストユーザー向けの設定
add_filter('tec_events_seo_robots_meta_content', function($robots_meta_content) {
if (!is_user_logged_in()) {
return 'noindex';
}
return $robots_meta_content;
});
このコードは、ログインしていないユーザーに対して、イベントページをインデックスさせない設定を行います。
この関数のアクションでの使用可能性
アクション | 使用可能性 |
---|---|
mu_plugin_loaded | |
registered_post_type | |
plugins_loaded | |
wp_roles_init | |
setup_theme | |
after_setup_theme | |
set_current_user | |
init | |
register_sidebar | |
wp_loaded | |
send_headers | |
parse_query | |
pre_get_posts | |
wp | |
template_redirect | |
get_header | |
wp_head | 〇 |
この表は tec_events_seo_robots_meta_content
フィルタがどのアクションで使用される可能性があるかを示しています。