ワードプレスのremove_post_type_support関数の使用方法・解説

概要

remove_post_type_support 関数は、特定の投稿タイプからサポートする機能を削除する際に使用されます。この関数を使用することで、カスタム投稿タイプから特定の機能を無効にすることができ、管理画面や投稿タイプの使用感をカスタマイズできます。主に以下のような機能を削除する場合に利用されます。

  1. 著者
  2. アイキャッチ画像
  3. カスタムフィールド
  4. エディタ
  5. 抜粋
  6. コメント
  7. パスワード保護
  8. リビジョン

構文

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');

このコードは、通常の投稿からエディタ機能を削除します。

この関数について質問する


上の計算式の答えを入力してください