概要
remove_post_type_support 関数は、特定の投稿タイプからサポートする機能を削除する際に使用されます。この関数を使用することで、カスタム投稿タイプから特定の機能を無効にすることができ、管理画面や投稿タイプの使用感をカスタマイズできます。主に以下のような機能を削除する場合に利用されます。
- 著者
- アイキャッチ画像
- カスタムフィールド
- エディタ
- 抜粋
- コメント
- パスワード保護
- リビジョン
構文
remove_post_type_support( $post_type, $support );
パラメータ
$post_type(string): 機能を削除したい投稿タイプのスラッグ$support(string): 削除する機能の名前
戻り値
この関数は返り値はありません。
関連する関数
使用可能なバージョン
この関数は、WordPress 2.9.0 以降で使用可能です。
コアファイルのパス
wp-includes/post.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 remove_featured_image_support() {
remove_post_type_support('post', 'thumbnail');
}
add_action('init', 'remove_featured_image_support');
このコードは、通常の投稿タイプからアイキャッチ画像機能を削除します。
サンプルコード2: コメント機能を削除
function remove_comments_support() {
remove_post_type_support('page', 'comments');
}
add_action('init', 'remove_comments_support');
このコードは、ページタイプからコメント機能を削除します。
サンプルコード3: カスタムフィールドを削除
function remove_custom_fields_support() {
remove_post_type_support('post', 'custom-fields');
}
add_action('init', 'remove_custom_fields_support');
このコードは、通常の投稿からカスタムフィールド機能を削除します。
サンプルコード4: 抜粋機能を削除
function remove_excerpt_support() {
remove_post_type_support('post', 'excerpt');
}
add_action('init', 'remove_excerpt_support');
このコードは、通常の投稿から抜粋機能を削除します。
サンプルコード5: エディタを削除
function remove_editor_support() {
remove_post_type_support('post', 'editor');
}
add_action('init', 'remove_editor_support');
このコードは、通常の投稿からエディタ機能を削除します。