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

I am modifying a custom post type's post list screeen and I want to remove all of the stuffs on the tablenav head like what is marked in the following image.

Is wordpress have special hook for that, or will I need to use the dirty way?

Topic wp-list-table list custom-post-types Wordpress

Category Web


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


The answer provided by @birgire is a solid programmatic way of handling the request but as he pointed out, his solutions gets a little tricky since WP core is missing an important filter.

To simply suppress, my preferred method would be CSS. Lets assume your custom post type is called "Event" this CSS will reliably do the trick:

.post-type-event .subsubsub,
.post-type-event .posts-filter .tablenav .actions,
.post-type-event .posts-filter .tablenav .view-switch,
.post-type-event .posts-filter .tablenav .tablenav-pages,
.post-type-event .posts-filter .search-box {
    display: none;
}

To ensure these styles are loaded on the WordPress dashboard be sure to enqueue it via the "admin_enqueue_scripts" hook using the wp_enqueue_style() helper.

EDIT: Updated the styles to separate "Actions" "View Icons" and "Pagination" into separate styles. Since pagination is pretty important I thought you might want to keep it. Simply deleting this line from the code above will show pagination but hide everything else:

.post-type-event .posts-filter .tablenav .tablenav-pages,

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.