# Hide the Current Post From the Recent Posts Widget

> Stops the classic Recent Posts widget from listing the post that is currently being viewed.

- Type: PHP
- Runs: Run everywhere
- Category: [Widgets](https://wpide.com/library/category/widgets/)
- Tags: widgets, recent-posts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/recent-posts-widget-exclude-current/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide the Current Post From the Recent Posts Widget" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
