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 →
PowerWP PRO WordPress Theme

PowerWP PRO

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

$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...

$30.00
BoxWP PRO WordPress Theme

BoxWP PRO

If you like BoxWP free WordPress Theme, you will love the premium version. BoxWP PRO is an elegant, user-friendly, feature-rich,...

$25.00
GridPal PRO WordPress Theme

GridPal PRO

If you like the GridPal Free WordPress Theme, then you will love the premium version. GridPal PRO version has color...

$35.00
EasyWP PRO WordPress Theme

EasyWP PRO

If you like EasyWP free WordPress Theme, you will love the premium version. EasyWP PRO is an user friendly, HTML5/CSS3...

$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+...

$35.00
GridShow PRO WordPress Theme

GridShow PRO

GridShow PRO WordPress theme is a feature-rich, advanced version of GridShow Free WordPress Theme. GridShow PRO version has color and...

$35.00
BlogWP PRO WordPress Theme

BlogWP PRO

If you like BlogWP free WordPress Theme, you will love the premium version. BlogWP PRO is easy to use, feature-rich,...

$30.00

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

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