Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

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.

share|improve this answer
    
This seems ideal, thanks again Milo I'll give it a try. –  Mr.Brown Nov 7 '11 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)? –  Mayeenul Islam Jul 1 '13 at 8:26
2  
@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 '13 at 15:23
    
@Milo: Excellent. Thank you. :) –  Mayeenul Islam Jul 1 '13 at 20:10
add comment

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

share|improve this answer
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 '11 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? –  Fulvio Apr 12 '12 at 8:14
    
Thanks @anmari for sharing this approach, really helpful. –  Maor Barazany Dec 6 '13 at 22:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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