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:
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:
You must be logged in to post a comment.
You can remove the default meta boxes with remove_meta_box and re-add them in a different position with add_meta_box:
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.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.)
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.