概要
remove_theme_support関数は、ワードプレスのテーマから特定の機能を削除する際に使用されます。この関数を利用することで、不要な機能を無効化し、テーマのカスタマイズやパフォーマンスを向上させることができます。一般的に、この関数は次のような機能を削除する際に使用されます。
- サムネイル画像のサポート
- 投稿フォーマットのサポート
- タイトルタグのサポート
- カスタム背景のサポート
- カスタムヘッダーのサポート
- 自動フィードリンクのサポート
- Gutenbergエディターのサポート
- ウィジェットエリアのサポート
構文
remove_theme_support( string $feature );
パラメータ
- $feature (string) – 削除したい機能の名前。具体的には、’post-thumbnails’や’custom-header’など。
戻り値
- なし。この関数は機能を削除するためのものであり、値を返しません。
関連する関数
使用可能なバージョン
- この関数はWordPress 3.0.0以降で使用可能です。
コアファイルのパス
wp-includes/theme.php
この関数のアクションでの使用可能性
| アクション | 使用可能性 |
|---|---|
| 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 |
サンプルコード
サンプルコード1: サムネイル画像のサポートを削除する
function mytheme_setup() {
remove_theme_support('post-thumbnails');
}
add_action('after_setup_theme', 'mytheme_setup');
このコードは、テーマのセットアップ時にサムネイル画像のサポートを削除します。サムネイル画像を使用しない場合、無駄なデータの生成を避けることができます。
引用元: https://developer.wordpress.org/reference/functions/remove_theme_support/
サンプルコード2: カスタムヘッダーのサポートを無効化する
function mytheme_remove_custom_header() {
remove_theme_support('custom-header');
}
add_action('after_setup_theme', 'mytheme_remove_custom_header');
このサンプルでは、カスタムヘッダーの機能をテーマから削除しています。これにより、ヘッダー画像の設定が無効になります。
引用元: https://developer.wordpress.org/reference/functions/remove_theme_support/
サンプルコード3: カスタム背景のサポートを削除する
function mytheme_disable_custom_background() {
remove_theme_support('custom-background');
}
add_action('after_setup_theme', 'mytheme_disable_custom_background');
ここでは、カスタム背景のサポートを無効化することで、テーマのデザインをよりシンプルに保つことができます。
引用元: https://developer.wordpress.org/reference/functions/remove_theme_support/
サンプルコード4: 自動フィードリンクのサポートを削除する
function mytheme_disable_feedlinks() {
remove_theme_support('automatic-feed-links');
}
add_action('after_setup_theme', 'mytheme_disable_feedlinks');
このコードは、自動フィードリンク機能を削除します。特にフィードリンクを必要としないサイトに適しています。
引用元: https://developer.wordpress.org/reference/functions/remove_theme_support/
サンプルコード5: 投稿フォーマットのサポートを無効化する
function mytheme_remove_post_formats() {
remove_theme_support('post-formats');
}
add_action('after_setup_theme', 'mytheme_remove_post_formats');
このサンプルでは、投稿フォーマットの機能を削除しています。これにより、特定のフォーマットに制限されない投稿が可能になります。
引用元: https://developer.wordpress.org/reference/functions/remove_theme_support/