How to Display Custom Post Types on Homepage in WordPress

By default, your WordPress website's blog homepage displays the "post" post type in reverse chronological order, with the most recently published "post" post type at the top. If you use custom post types, you may want to display recent posts of a custom type on your blog homepage with or without default "post" post type.

Let's say you have a custom post type called "books". You can display "books" post type on the homepage by choosing a code given below according to your needs and adding it to your theme's "functions.php" file.

Code 1:

Display "post" and "books" post types on the homepage:

function themesdna_custom_posts_types_on_homepage( $query ) {
    if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
        $query->set( 'post_type', array( 'post', 'books' ) );
    }
}
add_action( 'pre_get_posts', 'themesdna_custom_posts_types_on_homepage' );

Code 2:

Display "post" and "books" post types on the homepage, archive pages (category pages, tag pages,...), search pages:

function themesdna_custom_posts_types_on_nonsingular_pages( $query ) {
    if( $query->is_main_query() && ! is_admin() && ( $query->is_home() || $query->is_search() || $query->is_archive() ) ) {
        $query->set( 'post_type', array( 'post', 'books' ) );
    }
}
add_action( 'pre_get_posts', 'themesdna_custom_posts_types_on_nonsingular_pages' );

Our WordPress Themes

Below are some of our premium WordPress themes. View all our free and premium WordPress themes →
CuteWP PRO WordPress Theme

CuteWP PRO

If you like CuteWP free WordPress Theme, you will love the premium version. CuteWP PRO is an improved version of...

$25.00
GridBit PRO WordPress Theme

GridBit PRO

Are you looking for a feature-rich version of the GridBit Free WordPress Theme? Then you will fall in love with...

$25.00
GridMode PRO WordPress Theme

GridMode PRO

Are you using the GridMode free WordPress Theme and looking for more advanced features? GridMode PRO theme is developed for...

$25.00
GridView PRO WordPress Theme

GridView PRO

GridView PRO is fully responsive, feature-rich, accessibility improved, more advanced version of its free version. GridView PRO WordPress theme has...

$25.00
MagShow PRO WordPress Theme

MagShow PRO

MagShow PRO is the premium version of MagShow free WordPress Theme with more advanced features. MagShow PRO version has 160+...

$25.00
GridHot PRO WordPress Theme

GridHot PRO

If you have tried GridHot Free WordPress Theme, then you will love the premium version. GridHot PRO version has color...

$25.00
RapidWP PRO WordPress Theme

RapidWP PRO

Did you try RapidWP Free WordPress Theme?, Then you will love the premium version. RapidWP PRO is an improved, more...

$25.00
HotWP PRO WordPress Theme

HotWP PRO

If you like HotWP free WordPress Theme, you will love the HotWP premium version. HotWP PRO is easy to use,...

$25.00

Can't you choose a single theme? Purchase All Themes for $75.

Save money with our low, one-time price for access to all of our 56 WordPress themes.