If you use the Jetpack plugin, you’re probably familiar with the Stats module. Once you’ve activated the module, you can also use the Top Posts widget to display a list of the most popular posts on your site.
But what if there is one post that you never want to display there, even if it’s a popular one? You can exclude specific posts from the widget thanks to the jetpack_widget_get_top_posts
filter.
To do so, paste the following code into a functionality plugin:
function jeherve_remove_post_top_posts( $posts, $post_ids, $count ) { foreach ( $posts as $k => $post ) { // Replace 1215 by the ID of the Post you want to remove if ( '1215' == $post['post_id'] ) { unset( $posts[$k] ); } } return $posts; } add_filter( 'jetpack_widget_get_top_posts', 'jeherve_remove_post_top_posts', 10, 3 );
One reply on “Jetpack: remove a post from the Top Posts Widget”
Simple and easy to learn, thanks for sharing it with us :)