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

I am attempting to exclude all sticky posts from my front page in twenty twelve theme. I have attempted the following. I am making all changes to the child theme.

  1. To remove the following code from content.php

    <?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
    <div class="featured-post">
        <?php _e( 'Featured post', 'twentytwelve' ); ?>
    <?php endif; ?>
  2. Add following code to index.php before the loop(this removed sticky posts but broke pagination)

    <?php query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ) ) ); ?>

This is the loop in index.php (pretty much standard index.php for twenty twelve.

        <?php while ( have_posts() ) : the_post(); ?>
            <?php get_template_part( 'content', get_post_format() ); ?>

        <?php endwhile; ?>

        <?php twentytwelve_content_nav( 'nav-below' ); ?>

Could someone please advise me on what I should exactly put into this loop to not show any sticky posts on index.php?

Thank you for your time.

share|improve this question
up vote 4 down vote accepted

Don't use query_posts. Use a filter on pre_get_posts.

function no_front_sticky_wpse_98680($qry) {
  if (is_front_page()) {
    $qry->set('post__not_in',get_option( 'sticky_posts' ));

By running query_posts you clobber the main query, over-writing it with another query. That is why you break pagination. The new query gets out of sync with what should be the main query.

share|improve this answer
I assume you would add this above to functions.php, but would I need to add anything inside the loop of index.php such as <?php no_front_sticky_wpse_98680() ?> – UkrVolk11 May 8 '13 at 3:50
Just add it to functions.php. Nothing else is required. That will modify the main query for the front page. – s_ha_dum May 8 '13 at 4:12
Thank you for your help, its greatly appreciated – UkrVolk11 May 8 '13 at 15:08
@UkrVolk11 : if this solved the problem please mark it as "Accepted" – s_ha_dum May 8 '13 at 15:10

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.