How To Remove These Stuffs From Custom Post Type List Screen?

I don’t know what you mean by dirty way, hopefully not core editing!

You can hide it with CSS.

Or you can do it with PHP – see below:

Hide the views part

You can remove the views part with

add_filter( 'views_edit-post', '__return_null' );

for the post post type on the edit.php screen.

The post table object is created from:

$wp_list_table = _get_list_table('WP_Posts_List_Table');

but there’s no filter available in the _get_list_table() function.

Workaround – Extending the WP_Posts_List_Table class

So here’s a workaround by extending the WP_Posts_List_Table class and override it’s methods within the views_edit-post filter – Don’t try this at home! 😉

/**
 * Headless post table
 * 
 * @link http://wordpress.stackexchange.com/a/205281/26350
 */
add_action( 'load-edit.php', function()
{
    // Target the post edit screen
    if( 'edit-post' !== get_current_screen()->id )
        return;

    // Include the WP_Posts_List_Table class
    require_once ( ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php' );

    // Extend the WP_Posts_List_Table class and remove stuff
    class WPSE_Headless_Table extends WP_Posts_List_Table
    {
        public function search_box( $text, $input_id ){} // Remove search box
        protected function pagination( $which ){}        // Remove pagination
        protected function display_tablenav( $which ){}  // Remove navigation
    } // end class

    $mytable = new WPSE_Headless_Table; 
    // Prepare our table, this method has already run with the global table object
    $mytable->prepare_items();

    // Override the global post table object
    add_filter( 'views_edit-post', function( $views ) use ( $mytable )
    {
        global $wp_list_table;    
        // Let's clone it to the global object
        $wp_list_table = clone $mytable;
        // Let's remove the views part also
        return null;
    } );    
} );

Here’s a screenshot example:

Before:

before

After:

after

Leave a Comment