How to Enable Sticky Posts in WordPress Themes

By Posted 2009 Updated   BloggingWordPress

Sticky feature was introduced in WordPress 2.7 which let WordPress blogs highlight and send to top an important post on the front page despite the date of publication. But our theme did not support this feature when we selected the sticky checkbox.

 

Enable Sticky Posts in WordPress template

sticky on front page

If you are using a WordPress 2.7 compatible WordPress theme, then it will work out of the box without any of these tweaks. If you use an older theme, it actually works in 5 easy steps.

  1. In index.php add the tag
    <div <?php post_class(); ?>>
    before the article title and main post content

    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>

  2. Close the div tag at the end with </div>
  3. Add .sticky css tag to your stylesheet style.css, and choose the attributes which will highlight the articles above other articles
    .sticky {
    background: #ff0000;
    border: 1px solid #ccc;
    }
  4. Mark a post as sticky from the Quick Edit panel
  5. Visit your homepage, and check the Sticky post

The best part about this feature is you can easily change the sticky tag from the Quick Edit menu from the WP Admin, which makes it easy to quickly keep changing the featured articles on the front page, and even mark multiple articles as sticky.

sticky post

Can you spot the sticky post on our homepage? Now you can do this too.


11 comments on “How to Enable Sticky Posts in WordPress Themes

  1. vbb says:

    Just before you posted it,i have made a sticky post for my blog.However,being a newbie it was a very hard job.Finding the loop and then post_class output.
    Your tutorial is really simple,hope you had posted it two days before,it would have saved my time and frustration.

  2. Toby says:

    Thanks so much for this Sticky tutorial! I just got my stickies up and running thanks to it!

  3. kate says:

    Hi Sorry, I am using the minimal 1.1 theme (theme page here – http://rizzlestudios.ath.cx/) and i can’t find where to paste the code. Sorry, i’m a newbie. Also are you supposed to paste all three bits together?? Any help would be great! :)

  4. kate says:

    Ignore me, figured it out!! If any one knows how to hide the comment box and date from the sticky post that would be very handy too, thanks :)

  5. Home Based Jobs says:

    Is there any way to stick posts to pages other than the home page?

  6. Allen says:

    thanks for the tips on sticky posts, i came from performancing.com, and find this tutorial! thanks useful.

  7. sarasotarealestate says:

    this is a very nice post for online jobs.i agree with you.
    Is there any way to stick posts to pages other than the home page?
    Thanks so much for this Sticky tutorial! I just got my stickies up and running thanks to it!

  8. Write Stories Online says:

    Thanks so much for that! I needed that :)

  9. tuition agency says:

    Been looking for helps regarding this for my wordpress blog.

    Great tips.

    Thanks a lot!

  10. Carmen Brodeur says:

    Thanks for the tips. I have not heard of sticky posts before but that makes a lot of sense. I have several posts on my blog that are my favorites and I would like to see them up at the top.

  11. digitalsolution says:

    thanks for this good tutorial. I have 1 question. Can i show only 5 sticky post when i have more than 5?

Leave a Reply

Your email address will not be published. Required fields are marked *




css.php