How to Enable Sticky Posts in WordPress Themes

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.

Share with friends

About the Author: P Chandra is editor of QOT, one of India's earliest tech bloggers since 2004. A tech enthusiast with expertise in coding, WordPress, web tools, SEO and DIY hacks.