Remove custom meta boxes from custom post type

Is there a way to create a custom post type in WordPress that will only include the default meta boxes and not any other meta box that was added by other plugins?

The idea is to use the custom post to develop a plugin, this plugin will need to have all the functions custom post type but with all the meta boxes that the plugin adds like All in One SEO.

Read More

I want to create a clean interface for the user and those extra meta boxes are in the way 🙂

Related posts

5 comments

  1. Off the top of my head, without actually testing it, this should work. You want to test for is_admin so we don’t go running the code on the front end, then also test for the post type being equal to its slug. Edited this because I made a silly mistake before.

    Reference this page of the Codex: http://codex.wordpress.org/Function_Reference/remove_meta_box

    if( is_admin() ) {
        remove_meta_box('linktargetdiv', '$posttype', 'normal');
        remove_meta_box('linkxfndiv', '$posttype', 'normal');
        remove_meta_box('linkadvanceddiv', '$posttype', 'normal');
        remove_meta_box('postexcerpt', '$posttype', 'normal');
        remove_meta_box('trackbacksdiv', '$posttype', 'normal');
        remove_meta_box('postcustom', '$posttype', 'normal');
        remove_meta_box('commentstatusdiv', '$posttype', 'normal');
        remove_meta_box('commentsdiv', '$posttype', 'normal');
        remove_meta_box('revisionsdiv', '$posttype', 'normal');
        remove_meta_box('authordiv', '$posttype', 'normal');
        remove_meta_box('sqpt-meta-tags', '$posttype', 'normal');
    }
    
  2. You can find the best answer here:
    http://codex.wordpress.org/Function_Reference/remove_meta_box

    Certain meta boxes can be removed by adding something like the code below to the functions.php file in your WordPress theme:

    // hide certain meta boxes on the 'YOUR_CUSTOM_POST_TYPE' custom post type
    add_filter('add_meta_boxes', 'hide_meta_boxes_YOUR_CUSTOM_POST_TYPE');
    function hide_meta_boxes_YOUR_CUSTOM_POST_TYPE() {
        remove_meta_box('postexcerpt', 'YOUR_CUSTOM_POST_TYPE', 'normal');
        remove_meta_box('trackbacksdiv', 'YOUR_CUSTOM_POST_TYPE', 'normal');
        remove_meta_box('postcustom', 'YOUR_CUSTOM_POST_TYPE', 'normal');
        remove_meta_box('slugdiv', 'YOUR_CUSTOM_POST_TYPE', 'normal');
        remove_meta_box('commentstatusdiv', 'YOUR_CUSTOM_POST_TYPE', 'normal');
        remove_meta_box('commentsdiv', 'YOUR_CUSTOM_POST_TYPE', 'normal');
        remove_meta_box('revisionsdiv', 'YOUR_CUSTOM_POST_TYPE', 'normal');
    }
    
  3. Along with the other answers I found that if you create your Custom post type with

    $args = array(
        ...
        public => false
        ...
    ) 
    

    Some metaboxes won’t be included such as WordPress Seo by Yoast for example. On my case im Using the cpt for a popup, so other metaboxes are not needed and the cpt is not needed to be public.

  4. some times adding the style display none is a bad option for this purpose work very well and does not make errors on the program.
    I am using this technique to remove meta boxes from custom post types and normal posts and pages.

    to remove the meta box take the main id of the meta box for this you can consult the inspect tool with the right-click option

    to make this work just take the meta box id and add a style display: none;

    #metab-box-id {
      display:none;
          }
    
  5. First of all you shouldn’t do it. If a user have installed other plugins, it is because he/she want ot use it, even if your plugin provide all functionalities of that plugins, who say that for the users your plugin is better than others?

    And if that users already have tons of settings with other plugins and see them disappear installing your plugin? I bet that users immediately unistall your plugin (and if there is possibility very low votes will come in that case).

    Also consider that another plugin can use the same technique to remove your metaboxes. An the another plugin will remove the metaboxes of that plugin, and so on…

    What it will be, the war of metaboxes?

    My suggestion is to add your metaboxes and let users decide what metaboxes to leave and what to remove (unistalling plugin or unchecking the metabox from the “screen help” tab).

    Finally, note that you can’t remove metaboxes of a plugin if you don’t know the id of those metaboxes. So to do what you want you should install all your “competitors” plugins, look at the id of their metaboxes and remove them using remove_meta_box.

    And if a plugin get updated and change the id of its metaboxes?

    Believe me, it’s and hard, dirty, no-benefit work.

Comments are closed.