3

I'm looking for a way to move my custom taxonomy metabox (on the right side) to the post area (the middle). I'm aware you can simply drag and drop it, but I want it in the post area by default for new users.

My approach was to remove it using remove_meta_box(), and then add it back using add_meta_box(). The problem is that I don't know what callback function to call when adding it back.

/* Remove movies metabox from sidepanel */
function hide_metabox(){
    remove_meta_box( 'tagsdiv-movies', 'movies' , 'side' );
}
add_action( 'admin_menu' , 'hide_metabox' );


/* Add back movies metabox, but in post area */
add_action('add_meta_boxes', 'add_back_post');
    function add_back_post(){
    /* Not sure what to put as the thrid argument */
    add_meta_box('tagsdiv-movies','Movies', 'WHAT_CALLBACK_ARG', 'movies', 'normal', 'high');
}

Custom metabox "movies"

As a side note, I created the taxonomy using Custom Post Type UI (CPT UI) which basically follows the standard procedure when creating a custom taxonomy.

I'm not sure either if this answers my question as I don't quite follow the information provided here: Is there a predefined callback function for custom categories?.

5

The callback you need for non-hierarchical taxonomies is post_tags_meta_box.

The callback you need for hierarchical taxonomies is post_categories_meta_box.

For your example, the code would be:

/* Remove movies metabox from sidepanel */
function hide_metabox(){
    remove_meta_box(
        'tagsdiv-movies',
        'your-post-type' ,
        'side'
    );
}
add_action( 'admin_menu' , 'hide_metabox' );


/* Add back movies metabox, but in post area */
add_action('add_meta_boxes', 'add_back_post');
    function add_back_post(){
    add_meta_box(
        'tagsdiv-movies',
        'Movies',
        'post_tags_meta_box',
        'your-post-type',
        'normal',
        'high',
        array( 'taxonomy' => 'movies' )
    );
}

One other important variable is the metabox ID. In your example, tagsdiv-movies targets a metabox for a non-hierarchical taxonomy with slug movies. If that same taxonomy was hierarchical, the ID would be moviesdiv.

| improve this answer | |
  • 1
    You are godsent! I tried post_tags_meta_box before, but I was missing the array argument! This solved my 2 days of headache, thank you! – Dom Feb 27 '18 at 19:08
  • Indeed the array with the taxonomy seemed to fix for me too. – user1676224 Apr 4 '18 at 15:47

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.