Limit posts only on home page - ideally in functions.php

by Lori L   Last Updated August 01, 2020 09:08 AM - source

I'd like to restrict the number of posts that show on my home page to 3, but have all the other archive, category, pagination pages, etc. at whatever number I set in the "reading" settings in the Wordpress dashboard.

Is there a nice way to do this in functions.php?

I tried the following, which does limit the posts on the home page to 3, but it also creates pagination links to pages with 3 posts each.

    add_action( 'pre_get_posts',  'change_posts_number_home_page'  );
function change_posts_number_home_page( $query ) {

if ($query->is_home() && $query->is_main_query() ) {
        $query->set( 'posts_per_page', 3 );

return $query;

Thanks in advance!

Related Questions

entire tag list not getting fetched

Updated October 05, 2017 05:08 AM

method to fetch entire tag list on archive.php

Updated October 05, 2017 15:08 PM