How to force one column layout on custom post type edit page?

I’ve created a plugin using custom post types and I need to force the default two column post page to a single column. At the same time, the Publish metabox must move to the bottom. I need to do this via the functions some how.

I have some solutions from WPSE, but the only solution I’ve found actually hides the “Publish” metabox. I can’t seem to figure out why.

Read More

Any ideas of how to do this?

Related posts

Leave a Reply

3 comments

  1. There is a filter called get_user_option_meta-box-order_{$page} where $page is the name of the post type. Just make sure that submitdiv is the last value in the array:

    add_filter( 'get_user_option_meta-box-order_post', 'wpse25793_one_column_for_all' );
    function wpse25793_one_column_for_all( $order )
    {
        return array(
            'normal'   => join( ",", array(
                'postexcerpt',
                'formatdiv',
                'trackbacksdiv',
                'tagsdiv-post_tag',
                'categorydiv',
                'postimagediv',
                'postcustom',
                'commentstatusdiv',
                'slugdiv',
                'authordiv',
                'submitdiv',
            ) ),
            'side'     => '',
            'advanced' => '',
        );
    }
    
  2. One approach is to remove the original metabox, and then to re-add that metabox, with updated parameters. For example, this will move the “Featured Image” meta box from the side column to the main column, for a custom post type with a slug cpt-slug:

    Edit

    The parameter for the Publish meta box is submitdiv, and the correct callback is post_submit_meta_box(); I’ve updated the code below to reflect these correct parameters. I’ve also changed the add_meta_box() $context parameter from 'high' to 'low', so that the Publish meta box will be added at the bottom:

    <?php
    function wpse25793_move_post_metaboxes( $post ) {
        global $wp_meta_boxes;
    
        remove_meta_box( 'submitdiv', 'cpt-slug', 'side' );
        add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'cpt-slug', 'normal', 'low' );
    }
    add_action( 'add_meta_boxes_cpt-slug', 'wpse25793_move_post_metaboxes' );
    ?>
    

    The approach should be the same for the “Publish” meta box. You just need to remove/add the publish meta box instead of the featured image meta box.

  3. To answer the second part of the question – How to force one column, you can do it with get_user_option_screen_layout_{Post_type} filter. Let’s say for product post-type:

    $func = function( $result, $option, $user ){
        return '1';
    };
    add_filter( "get_user_option_screen_layout_product", $func, 10, 3 );