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

TidyMag PRO

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

$25.00
CleanWP PRO WordPress Theme

CleanWP PRO

If you like CleanWP free WordPress Theme, you will love the CleanWP PRO version. The premium version of CleanWP WordPress...

$25.00
Clean Gallery PRO WordPress Theme

Clean Gallery PRO

If you like Clean Gallery free WordPress Theme, you will love the premium version. Clean Gallery PRO is an elegant,...

$25.00
Simple Writer PRO WordPress Theme

Simple Writer PRO

Simple Writer PRO is a feature-rich, improved and advanced version of Simple Writer Free WordPress Theme. When compare with the...

$25.00
FreshWP PRO WordPress Theme

FreshWP PRO

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

$25.00
GreatWP PRO WordPress Theme

GreatWP PRO

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

$25.00
MagSoul PRO WordPress Theme

MagSoul PRO

$25.00
Clean Grid PRO WordPress Theme

Clean Grid PRO

If you like Clean Grid free WordPress Theme, you will love the premium version. Clean Grid PRO is an elegant,...

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