Hide the post count behind Post Views (Remove All, Published and Trashed) in Custom Post Type

I need to hide/remove the numbers behind the Edit screen in the backend.

All (30) | Published (22) | Draft (5) | Pending (2) | Trash (1)

As I am running a multi author blog and each author has just access to its own posts, I dont want to publish the cumulated information of all authors.

With the following code the views are completely unset, but I dont want to remove the whole functionality:

function remove__views( $views ) {
unset($views['all']);
unset($views['publish']);
unset($views['trash']);
return $views;
}
add_action( 'views_edit-post',  'remove_views' );
add_action( 'views_edit-movie', 'remove_views' );

Has anybody an idea, how I can either hide/remove the numbers behind the edit screen or – at best – to show only the numbers related to each author?

4 s
4

There is, unfortunately, no “pretty” way to do this (i.e. without using string replacing or rewriting a big chunck of functionality). So, resorting to preg_replace

We’ll need to filter the links, and it’s good to see that you’ve already found the proper filters! Looping through the views and using a regular expression, we can remove the element containing the post count. Implementing this for posts, you’ll need something like this:

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

function wpse149143_edit_posts_views( $views ) {
    foreach ( $views as $index => $view ) {
        $views[ $index ] = preg_replace( '/ <span class="count">\([0-9]+\)<\/span>/', '', $view );
    }

    return $views;
}

Leave a Comment