Make custom post type edit page one column

Just a quick snippet.

In case you need to make a custom post type screen be one column, you need to add/modify two filters. This example uses CPT_Core:

<?php

class My_Site_Posts_CPT extends CPT_Core {

  /**
   * Register Custom Post Types. See documentation in CPT_Core, and in wp-includes/post.php
   */
  public function __construct() {

    // Register this cpt
    // First parameter should be an array with Singular, Plural, and Registered name
    parent::__construct(
      array( __( 'Site Post', 'wds-reports' ), __( 'Site Posts', 'wds-reports' ), 'site-posts' ),
      array(
        'public'             => false,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => 'edit.php?post_type=report',
        'rewrite'            => false,
        'capability_type'    => 'post',
        'has_archive'        => false,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'author', 'thumbnail' ),
      )
    );

    add_filter( 'screen_layout_columns', array( $this, 'set_column_num_max_to_one' ), 10, 3 );
    add_filter( 'get_user_option_screen_layout_site-posts', array( $this, 'make_one_col' ) );
  }

  public function set_column_num_max_to_one( $empty_columns, $screen_id, $screen ) {
    if ( $this->post_type() == $screen_id ) {
      $empty_columns[ $screen_id ] = 1;
    }
    return $empty_columns;
  }

  public function make_one_col( $result ) { return 1; }

}
new My_Site_Posts_CPT();

one-col-cpt-screenshot

Comment