If you are looking for ways to completely remove the All, Published, and Trash in WordPress admin dashboard posts or custom post types. Then this article will provide you with complete steps to make it possible for you.
By default, WordPress displays all pages/posts in the admin area’s list, regardless of whether they are published or not. If you will refer to the below screenshot then you can see the count of All, Published, and trash.
Now, we want to remove the All and trash option from the above image place. Sometimes you will get more options in your dashboard like pending, draft.
The WP_Posts_List_Table
class extends WP_List_Table
and within the WP_List_Table::views()
method we have the following dynamic views filter:
2 3 4 5 6 7 8 9 10 11 12 13 14 |
/** * Filter the list of available list table views. * * The dynamic portion of the hook name, `$this->screen->id`, refers * to the ID of the current screen, usually a string. * * @since 3.5.0 * * @param array $views An array of available list table views. */ $views = apply_filters( "views_{$this->screen->id}", $views ) |
So we can use the generated views_edit-post
filter to adjust the views of the post list table. I found this code to from here
Are you want to get implementation help, or modify or extend the functionality of this script?
A Tutorialswebsite Expert can do it for you.
Remove “All Posts, Published, and Trash” in Dashboard Posts
Let’s remove the all, publish, draft, pending, and trash for non-admins
You just simply copy and paste the following code to your theme functions.php file
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php /** * Remove the 'all', 'publish', 'draft', 'pending', 'trash' * views for non-admins */ add_filter( 'views_edit-post', function( $views ) { if( current_user_can( 'manage_options' ) ) // return $views; $remove_views = [ 'all', 'publish', 'draft', 'pending', 'trash' ]; foreach( (array) $remove_views as $view ) { if( isset( $views[$view] ) ) unset( $views[$view] ); } return $views; } ); |
In the above code, you can see the filter “view_edit-post” which only works for the post dashboard.
Remove “All Posts, Published, and Trash” for custom post type in Dashboard
If you have a custom post type then you need to modify the filter like “view_edit-custom-post-type”.
Also Read: How to display only published posts by default in the admin area?
For Example: Suppose I have a custom post type named recipe. then I will call the filter “view_edit-recipe”.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php /** * Remove the 'all', 'publish', 'draft', 'pending', 'trash' * views for non-admins */ add_filter( 'views_edit-recipe', function( $views ) // recipe custom post type { if( current_user_can( 'manage_options' ) ) // return $views; $remove_views = [ 'all', 'publish', 'draft', 'pending', 'trash' ]; foreach( (array) $remove_views as $view ) { if( isset( $views[$view] ) ) unset( $views[$view] ); } return $views; } ); |
Note: the “all” and “mine” status links are hard-coded in the get_views()
method of the WP_Posts_List_Table
Class and aren’t filterable.
Are you want to get implementation help, or modify or extend the functionality of this script? submit your paid request
Conclusion
Well, In this article you will get the complete steps to Disable (or Remove) “All Posts, Published, and Trash” in Dashboard Posts. You can extend the functionality as per your requirement. I hope you found this tutorial helpful for your project. Keep learning!.
Pradeep Maurya is the Professional Web Developer & Designer and the Founder of “Tutorials website”. He lives in Delhi and loves to be a self-dependent person. As an owner, he is trying his best to improve this platform day by day. His passion, dedication and quick decision making ability to stand apart from others. He’s an avid blogger and writes on the publications like Dzone, e27.co