WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

in home.php

// NOT working

// NOT working
add_action( 'pre_get_posts',  'set_posts_per_page'  );
function set_posts_per_page( $query ) {

    $query->set( 'posts_per_page', 3 );

    return $query;



I searched a lot, almost always they say the 2nd solution. But i does not work for me, maybe because its genesis. Or is this outdated?

I don't want to use the custom grid stuff i just want to limit the posts on one page (the homepage in this example)

solution thx to @Milo:

its just working in functions.php and there i need a additional if is_home

/** reduce number of posts on homepage **/
add_action( 'pre_get_posts',  'set_posts_per_page'  );
function set_posts_per_page( $query ) {

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

    return $query;
share|improve this question
Can you give us the hole home.php file? And try to set the limit under Settings-> Reading -> Blog post and see if that works – Pontus Abrahamsson Jun 8 '12 at 16:54
I reduced the home.php to exactly that now. So something is wrong about that code. And the settings work just as expected. – amy Jun 8 '12 at 20:17
up vote 1 down vote accepted

1) use posts_per_page to set number of posts 2) your add_action and its associated function needs to be in your theme's functions.php file, not the template.

the pre_get_posts action is the preferred method between the two, use that one.

share|improve this answer
Thx, I taught templates are something like additional function.php's for specific pages. – amy Jun 8 '12 at 20:37
@amy functions.php is loaded early, where the hooks need to be added. a template is loaded after the query happens, so it's too late to add action hooks there. using query_posts generates a new query which overwrites the original, which is less efficient than just catching the first query before it happens. – Milo Jun 8 '12 at 20:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.