5

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.

enter image description here

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

10

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

  • Please be aware that this solution kills pagination on the list page (see screenshots provided by @birgire). The code can be modified to support pagination so the solution is absolutely viable. Just be sure to exercise caution. – dswebsme Oct 12 '15 at 15:57
  • yes it will remove the pagination, I just removed all the table navigation head, because of the OP's screenshot. But this is just an example how we could adjust the table to our needs. @dswebsme – birgire Oct 12 '15 at 16:46
  • Absolutely. I just wanted to caution the copy/paste users so they'd know what to expect =] Certainly not implying there is anything wrong with the answer. – dswebsme Oct 12 '15 at 16:56
  • thanks for the caution, there are too many that just copy/paste - I also added a silly notice in the answer ;-) When only hiding stuff I would in general just recommend CSS as you describe in your answer (+1) but this overriding method (just mentioned here for fun) might be better suited for modifications that are not available through hooks/css ;-) @dswebsme – birgire Oct 12 '15 at 17:01
  • 1
    Using css or jquery is what I meant by using the dirty way. – Ari Oct 12 '15 at 19:49
5

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,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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