(+84) 463.28.7979

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.

sticky on front page

Enable Sticky Posts in WordPress template

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.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>