6

I am using multipress, but users with small screens cannot access the HTML tab as the Publish meta box has a div that slides above it, disabling the ability to click it. One idea is to force a single column layout, but there are no options for this in screen options. Is there another way to do it?

0

7 Answers 7

18

You can use the filter screen_layout_columns to set only one column for the post screen get_user_option_screen_layout_post to force the user option to 1.

If you want to use that for custom post type then use get_user_option_screen_layout_{post_type}

The following code will do it:

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' );
5
  • I tried your code. Its working perfectly. But i see publish tab in the top of the page. Is there a way to move it bottom of the page by giving any priority? Dec 31, 2011 at 19:22
  • See here wordpress.stackexchange.com/questions/25793/…
    – sorich87
    Jan 2, 2012 at 7:00
  • I tried that code bro. But its not working. My post metabox order looks like this as of now. Title,submit,content,custom metaboxes added by plugins,tags Jan 2, 2012 at 7:42
  • Comment on the other answer then, so that it can be corrected.
    – sorich87
    Jan 2, 2012 at 8:37
  • thanks it works. just mention that how to use that for custom post type.
    – M Haseeb
    Nov 6, 2015 at 10:04
5

simply you can do that :

add_filter('get_user_option_screen_layout_{$post_type}', 'your_callback' );

example with "message" post type :

add_filter('get_user_option_screen_layout_message', function() {
   return 1;
} );

You can use '__return_true' in your callback.

see: http://codex.wordpress.org/Function_Reference/get_user_option

0
1

To clarify: there are options under Screen Options for forcing a one column layout, but they are only available choices when on an Wordpress editor page like Posts or Pages.

The Screen Options button appears like a tab next to the Help button in the top right corner of the Wordpress Dashboard.

@sorich87 has the best possible solution. Including that code in functions.php will force all users into one column layout in the editor, which could help alleviate confusion for less technical users.

1

This one worked for me:

$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' );

It will override the default option with whatever option a user has explicitly selected in the Screen Options panel in WP admin. This is better for usability in my opinion.

0
  • Use a theme that supports smaller widths.

    Edit your CSS directly.

    Add a CSS media query stylesheet.

0

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 );
0

Just add the below line into function.php

add_filter( "get_user_option_screen_layout_{post-type}", function(){return '1';}, 10, 3 );
1
  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    Jun 4, 2020 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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