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

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