remove_post_type_support( string $post_type, string $feature )

Remove support for a feature from a post type.


Description Description


Parameters Parameters

$post_type

(string) (Required) The post type for which to remove the feature.

$feature

(string) (Required) The feature being removed.


Top ↑

Source Source

File: wp-includes/post.php

function remove_post_type_support( $post_type, $feature ) {
	global $_wp_post_type_features;

	unset( $_wp_post_type_features[ $post_type ][ $feature ] );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 2 content
    Contributed by Codex

    Remove support for post formats
    This example removes support for post formats in posts:

    /**
     * Remove post-formats support from posts.
     */
    function wpdocs_remove_post_type_support() {
    	remove_post_type_support( 'post', 'post-formats' );
    }
    add_action( 'init', 'wpdocs_remove_post_type_support', 10 );
    
  2. Skip to note 3 content
    Contributed by arifktk

    Hide page visual editor if certain template is selected:

    add_action( 'init', 'remove_editor_init' );
    
    function remove_editor_init() {
        // If not in the admin, return.
        if ( ! is_admin() ) {
           return;
        }
    
        // Get the post ID on edit post with filter_input super global inspection.
        $current_post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
        // Get the post ID on update post with filter_input super global inspection.
        $update_post_id = filter_input( INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT );
    
        // Check to see if the post ID is set, else return.
        if ( isset( $current_post_id ) ) {
           $post_id = absint( $current_post_id );
        } else if ( isset( $update_post_id ) ) {
           $post_id = absint( $update_post_id );
        } else {
           return;
        }
    
        // Don't do anything unless there is a post_id.
        if ( isset( $post_id ) ) {
           // Get the template of the current post.
           $template_file = get_post_meta( $post_id, '_wp_page_template', true );
    
           // Example of removing page editor for page-your-template.php template.
           if (  'page-your-template.php' === $template_file ) {
               remove_post_type_support( 'page', 'editor' );
               // Other features can also be removed in addition to the editor. See: https://codex.wordpress.org/Function_Reference/remove_post_type_support.
           }
        }
    }

    Credit: https://wordpress.stackexchange.com/a/91644/138483

You must log in before being able to contribute a note or feedback.