# Hide Specific Posts From the Blog Page

> Keeps the posts you list off the main blog page and its pagination while they stay reachable through their own URL, categories and search.

- Type: PHP
- Runs: Run everywhere
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: blog, exclude, homepage
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/exclude-posts-from-blog-page/

## Code

```php
// IDs of posts to keep off the blog page.
$wpide_hidden_from_blog = array( 0 );

add_action( 'pre_get_posts', function ( $query ) use ( $wpide_hidden_from_blog ) {
    if ( is_admin() || ! $query->is_main_query() || ! $query->is_home() ) {
        return;
    }

    $query->set( 'post__not_in', array_merge( (array) $query->get( 'post__not_in' ), array_map( 'absint', $wpide_hidden_from_blog ) ) );
} );
```

## Notes

Add the post IDs to the list.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide Specific Posts From the Blog Page" 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/
