2

I created a custom-taxonomy for a custom-post-type which functions as kind of categories for this post-type.

The Metabox for my taxonomy has two tabs. One for my Categories and a second tab called "Most Used" just like the normal categories for normal posts has.

Is there a way to get rid of this "Most Used" tab?

Thanks in advance?

2

Yes - you need to first 'de-register' the metabox WordPress automatically creates:

add_action( 'admin_menu', 'myprefix_remove_meta_box');  
function myprefix_remove_meta_box(){  
   remove_meta_box('my-tax-metabox-id', 'post', 'normal');  
}  

Where my-tax-metabox-id is the ID of your metabox. Then 're-register' the metabox providing your own callback function which produces in the output:

//Add new taxonomy meta box  
 add_action( 'add_meta_boxes', 'myprefix_add_meta_box');  
 function myprefix_add_meta_box() {  
     add_meta_box( 'mytaxonomymetabox_id', 'My Taxonomy','myprefix_mytaxonomy_metabox','post' ,'side','core');  
 }  

  function myprefix_mytaxonomy_metabox( $post ) {  
     //This function determines what displays in your metabox
     echo 'This is my taxonomy metabox';  
  } 

Then it is simply a matter of mimicking the 'default' hierarchal metabox markup but removing the tabs. You might find this article I wrote, where I do this for a slightly different purpose, helpful. In short check out: http://core.trac.wordpress.org/browser/tags/3.3/wp-admin/includes/meta-boxes.php#L307

That is the function responsible for outputting hierarchal metaboxes - you'll want to change that slightly (removing the tabs, and defining the $taxonomy variable etc.

2

For anyone looking for a simpler solution, you can just add the following CSS to the backend, for example, assuming the taxonomy in question is "eventtype":

/* make sure tabs and the popular div itself are not shown */
#eventtype-pop,#eventtype-tabs{
    display: none !important;
}
/* make sure the All Terms div is always shown, and remove extra spacing and styles */
#eventtype-all,#eventtype-all,#eventtype-all ul,#eventtype-all ul{
    display: block !important;
    padding:0;
    margin:0;
    background: transparent;
    border:0;
}

You can add this CSS to an existing admin CSS or with a simple admin hook:

add_action('admin_head', 'adminCSS');

function adminCSS(){
    ?><style type='text/css'>
    /* make sure tabs and the popular div itself are not shown */
    #eventtype-pop,#eventtype-tabs{
        display: none !important;
    }
    /* make sure the All Terms div is always shown, and remove extra spacing and styles */
    #eventtype-all,#eventtype-all,#eventtype-all ul,#eventtype-all ul{
        display: block !important;
        padding:0;
        margin:0;
        background: transparent;
        border:0;
    }
    </style><?php
}

This example shows inline CSS, but you could very well add an external CSS with all the rules you need.

  • by adding <script type="text/javascript"> jQuery(document).ready(function($) { $("#eventtype-pop, #eventtype-tabs").remove(); }); </script> You can make sure the items are removed and not just hidden. – Frederik Voordeckers Jan 26 '15 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.