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?.

1 Answer
1

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.

Leave a Reply

Your email address will not be published. Required fields are marked *