How To Include Custom Post Types On Homepage In WordPress?

By default WordPress only allows users to display static pages and posts on the front page. There are many solutions for displaying any other post type on the homepage like by using shortcode plugins etc  but here we will provide you the easiest among all other solutions. We will be using a hack which you can easily enable on your website or alternatively you may also give a try to CPT on Front Page plugin by fabrizim.

Install and activate CPT on Front Page plugin in your WordPress installation and then visit your site’s reading settings (Dashboard -> Settings -> Reading) page and use the checkboxes for enabling the post types which you like showing up on the homepage.

If this plugin doesn’t works with your WordPress theme then…

Then deactivate this plugin, open your theme’s function.php file and use the following code replacing yourposttypename with the name of the custom post type you want to include on frontpage:

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

    if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type', array( 'post', 'page', 'yourposttypename' ) );

    return $query;
}

You can include as may post types you like. Simply add them in the above given hack using the same comma separated pattern.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.