admin管理员组文章数量:1127905
I am desperately looking for some way (any way) to set default "screen options" and metabox order through the functions.php file. does anyone have any help they can provide here?
I am desperately looking for some way (any way) to set default "screen options" and metabox order through the functions.php file. does anyone have any help they can provide here?
Share Improve this question asked Sep 5, 2010 at 23:44 NetConstructor.comNetConstructor.com 4,40618 gold badges70 silver badges82 bronze badges 1- 2014 Update: For those who just need to reorder meta boxes, see Nabil's answer below. – rinogo Commented Aug 10, 2017 at 21:10
3 Answers
Reset to default 25Setting the order of meta boxes on post edit pages
You will need to remove the meta boxes, and add them again in the order you want.
To disable meta boxes: (customize to your needs, look at the metabox id in the html code to know which name you should use as first parameter of the functions)
function my_remove_meta_boxes() {
remove_meta_box('postcustom', 'post', 'core');
remove_meta_box('commentsdiv', 'post', 'core');
...
}
add_action( 'admin_menu', 'my_remove_meta_boxes' );
After removing them, you can use the add_meta_box function to add them at new positions: http://codex.wordpress.org/Function_Reference/add_meta_box. The order of the meta boxes depends on the order in which you call the add_meta_box function. E.g.: with the following code snippet, the comments meta box will be before the custom fields meta box.
function my_add_meta_boxes( $post_type, $post ) {
if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core');
if ( post_type_supports($post_type, 'custom-fields') )
add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
...
}
add_action( 'add_meta_boxes', 'my_add_meta_boxes' );
You may want to look at the file wp-admin/edit-form-advanced.php
Setting which columns title show up on the post list page
You need to use the filter manage_{$post_type}_posts_columns. E.g.: the following snippet will remove the comments column.
function my_remove_columns( $posts_columns ) {
unset( $posts_columns['comments'] );
return $posts_columns;
}
add_filter( 'manage_post_posts_columns', 'my_remove_columns' );
Setting the default results to be shown on the post list page
Use the filters 'edit_{$post_type}_per_page' and 'edit_posts_per_page'.
function my_edit_post_per_page( $per_page, $post_type ) {
$edit_per_page = 'edit_' . $post_type . '_per_page';
$per_page = (int) get_user_option( $edit_per_page );
if ( empty( $per_page ) || $per_page < 1 )
$per_page = 1;
return $per_page;
}
add_filter( 'edit_posts_per_page', 'my_edit_post_per_page' );
To target a specific post type:
use
add_filter( 'edit_{post type}_per_page', 'my_edit_post_per_page' );
e.g.add_filter( 'edit_post_per_page', 'my_edit_post_per_page' );
for posts,add_filter( 'edit_page_per_page', 'my_edit_post_per_page' );
for pages.or use a condition within your function. e.g.:
function my_edit_post_per_page( $per_page, $post_type ) {
if( $post_type == 'post' ) { $edit_per_page = 'edit_' . $post_type . '_per_page'; $per_page = (int) get_user_option( $edit_per_page ); if ( empty( $per_page ) || $per_page < 1 ) $per_page = 1; } return $per_page;
In the following example, replace {CPT}
with the post type name, like post
, page
, book
, event
, imaginary
, foobar
... So if you have a post type named event
, you would need to add a filter for get_user_option_meta-box-order_event
.
add_filter( 'get_user_option_meta-box-order_{CPT}', 'metabox_order' );
function metabox_order( $order ) {
return array(
'normal' => join(
",",
array( // vvv Arrange here as you desire
'customdiv-{CPT}',
'authordiv',
'slugdiv',
)
),
);
}
Notes:
- Along with
normal
, you can also haveside
andadvanced
- The values are comma separated div ids, you can grab by view the page source code or you can guess
- Any metabox that exists isn't included in your custom order will be added automatically at the end of your list.
Is there a plugin that combines these codes pieces together so an admin can force the meta box positions for all users without coding.
Bad practice or not, when performing help desk with some less sophisticated users, it helps a lot to know what they are seeing and where it is on their screen. Forcing meta boxes to the same position for all users can be beneficial with certain users.
Ideally, users with role of admin could still reposition their meta boxes, but subscribers and contributors could benefit from seeing all meta poxes in the same positions.
Does such a plugin exist. I cannot seem to find one.
This plugin might even be an option as it just prevent users from moving meta boxes around, but it has not been updated in a decade. https://wordpress.org/plugins/unsortable-meta-box/
本文标签: Set Default Admin Screen options amp Metabox Order
版权声明:本文标题:Set Default Admin Screen options & Metabox Order 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736710626a1948923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论