我使用的是multipress,但屏幕较小的用户无法访问HTML选项卡,因为Publish meta框上有一个滑动的div,无法单击它。一个想法是强制使用单列布局,但屏幕选项中没有用于此的选项。还有别的方法吗?
如何在屏幕布局中强制使用单列布局
您可以使用过滤器screen_layout_columns
仅为post屏幕设置一列get_user_option_screen_layout_post
强制用户选项为1。
如果要将其用于自定义帖子类型,请使用get_user_option_screen_layout_{post_type}
以下代码将执行此操作:
function so_screen_layout_columns( $columns ) {
$columns[\'post\'] = 1;
return $columns;
}
add_filter( \'screen_layout_columns\', \'so_screen_layout_columns\' );
function so_screen_layout_post() {
return 1;
}
add_filter( \'get_user_option_screen_layout_post\', \'so_screen_layout_post\' );
您只需执行以下操作:
add_filter(\'get_user_option_screen_layout_{$post_type}\', \'your_callback\' );
“消息”帖子类型示例:add_filter(\'get_user_option_screen_layout_message\', function() {
return 1;
} );
您可以在回调中使用“\\u return\\u true”。请参见:http://codex.wordpress.org/Function_Reference/get_user_option
澄清一下:屏幕选项下有一些选项用于强制单列布局,但它们仅在Wordpress编辑器页面(如帖子或页面)上可用。
屏幕选项按钮显示为Wordpress仪表板右上角帮助按钮旁边的选项卡。
@sorich87提供了最好的解决方案。在函数中包含该代码。php将强制所有用户在编辑器中使用一列布局,这有助于减轻技术含量较低的用户的困惑。
这个对我很有用:
$post_type = \'post\'; // Change this to a post type you\'d want
function my_screen_layout_post( $selected ) {
if( false === $selected ) {
return 1; // Use 1 column if user hasn\'t selected anything in Screen Options
}
return $selected; // Use what the user wants
}
add_filter( "get_user_option_screen_layout_{$post_type}", \'my_screen_layout_post\' );
它将用用户在WP admin的屏幕选项面板中明确选择的任何选项覆盖默认选项。在我看来,这对可用性更好。使用支持较小宽度的主题。
直接编辑CSS。
添加CSS媒体查询样式表。
Just another alternative using the same techniques as accepted solution:
add_filter( \'screen_layout_columns\', function ( Array $columns = array() ) {
$current_screen = get_current_screen();
$screen_ids = array(); // Add screen ID\'s here
if ( in_array( $current_screen->id, $screen_ids ) ) {
$columns[ $current_screen->id ] = 1;
update_user_meta( get_current_user_id(), "screen_layout_{$current_screen->id}", 1 );
}
return $columns;
}, 9999 );
只需将下面的行添加到函数中。php
add_filter( "get_user_option_screen_layout_{post-type}", function(){return \'1\';}, 10, 3 );