Hide the Current Post From the Recent Posts Widget
Stops the classic Recent Posts widget from listing the post that is currently being viewed.
Opens WPIDE on
Code
add_filter( 'widget_posts_args', function ( $args ) {
if ( is_singular() ) {
$args['post__not_in'] = array_merge( isset( $args['post__not_in'] ) ? (array) $args['post__not_in'] : array(), array( get_queried_object_id() ) );
}
return $args;
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.