Want to set default screen options in WordPress? For that you don’t need a plugin, just drop the following into your functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | /** * Set default screen options in WordPress. */ function set_user_metaboxes($user_id=NULL) { // These are the metakeys we will need to update $meta_key['order'] = 'meta-box-order_post'; $meta_key['hidden'] = 'metaboxhidden_post'; // So this can be used without hooking into user_register if ( ! $user_id) $user_id = get_current_user_id(); // Set the default order if it has not been set yet if ( ! get_user_meta( $user_id, $meta_key['order'], true) ) { $meta_value = array( 'side' => 'submitdiv,formatdiv,categorydiv,postimagediv', 'normal' => 'postexcerpt,tagsdiv-post_tag,postcustom,commentstatusdiv,commentsdiv,trackbacksdiv,slugdiv,authordiv,revisionsdiv', 'advanced' => '', ); update_user_meta( $user_id, $meta_key['order'], $meta_value ); } // Set the default hiddens if it has not been set yet if ( ! get_user_meta( $user_id, $meta_key['hidden'], true) ) { $meta_value = array('postcustom','trackbacksdiv','commentstatusdiv','commentsdiv','slugdiv','authordiv','revisionsdiv'); update_user_meta( $user_id, $meta_key['hidden'], $meta_value ); } } add_action('admin_init', 'set_user_metaboxes'); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.