18

Im wondering if there is a way to change the default position of Wordpresses meta boxes such as "featured image" for custom post types without having to drag them manually?

Example: Meta Box Positioning Example

1

3 Answers 3

23

You can remove the default meta boxes with remove_meta_box and re-add them in a different position with add_meta_box:

add_action('do_meta_boxes', 'wpse33063_move_meta_box');

function wpse33063_move_meta_box(){
    remove_meta_box( 'postimagediv', 'post', 'side' );
    add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', 'post', 'normal', 'high');
}

This will remove it from the side column and add it to the main column. change post in this example to whatever your custom post type is named.

3
  • This seems ideal, thanks again Milo I'll give it a try.
    – Mr.Brown
    Nov 7, 2011 at 14:53
  • @Milo: As if the add_meta_box() needs a $callback function name, how come I know the name of the function used by WordPress? Suppose if I want to do the same thing to sidebar meta_box 'Categories' (#categorydiv)? Jul 1, 2013 at 8:26
  • 5
    @MayeenulIslam look in the file /wp-admin/edit-form-advanced.php and you will see where WordPress adds all core meta boxes and the callbacks and arguments it uses. for categories it is post_categories_meta_box.
    – Milo
    Jul 1, 2013 at 15:23
5

I struggled with this too. I didn't really find a clean way to redefine the layout/order - particularly since it can be changed by the users when/if they drag the boxes.

I like to do things 'with' wordpress (it usually pays off), rathe than clash with it and the way wordpress does it is as follows:

wordpress stores the dragged positions per user per screen and there are a whole bunch of user-meta keys that it uses depending on which page/screen it is on.

So you could add a action or filter for each new user to set the user setting the way you want the default to be.
1) Drag and arrange the page you want to affect, then 2)look in phpmyadmin at your user-meta for your id and see what wp has stored there. 3) then code new user action as follows if a user does NOT have that setting already set (to avoid overwriting a personal choice), you could set it the way you want - with the value you found from manually setting it.

To get the idea of the user-meta metakeys you are looking for, see these screenshots: http://wpusersplugin.com/related-plugins/amr-user-templates/screenshots-for-user-templates/

(I ended up writing a generic plugin so that i could as admin define my preferred layout for all users for all sorts of pages/screens. Then they could alter that eg as they became more proficient. Also it won't break when wp changes things as me plugin just fetches the template user values, it doesn't even try to set the value to a hardcoded value.)

3
  • 1
    Though I like the idea behind this approach, Milo's solution seems a lot faster so Im gonna give that a shot instead, but thank you for taking the time to inform me on this approach as well. I'll def look into using this way at a later date. I 1up'd your comment.
    – Mr.Brown
    Nov 7, 2011 at 14:55
  • 3
    Plugin proposed by Anmari is a paid commercial plugin... and doesn't look like updated since August past year. Are you still maintaining that plugin? If not, have you considered sharing it on Github?
    – unfulvio
    Apr 12, 2012 at 8:14
  • Thanks @anmari for sharing this approach, really helpful. Dec 6, 2013 at 22:53
0

If you want to order precisely your meta boxes, you can use this plugin : https://wordpress.org/plugins/post-meta-box-order/

It plays on the meta-box-order_post of the user option (table wp_usermeta).

Note 1: this technique can be applied to any custom CPT by changing the end of the flag : meta-box-order_[YOUR_CPT]

Note 2 : don't forget to change the hash in the code of the plugin to apply your new order to all existing users.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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