# Include Custom Post Types on the Blog Page

> Mixes entries from a custom post type into the main blog page and feed alongside regular posts.

- Type: PHP
- Runs: Run everywhere
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: archive, custom-post-types, blog, query
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/custom-post-types-on-blog/

## Code

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

    if ( $query->is_home() || ( $query->is_feed() && ! $query->is_comment_feed() && ! $query->get( 'post_type' ) ) ) {
        $query->set( 'post_type', array( 'post', 'portfolio' ) );
    }
} );
```

## Notes

Replace portfolio with your post type name(s).

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Include Custom Post Types on 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/
