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

11
Leave a Reply

avatar
11 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
10 Comment authors
digitalsolutionCarmen Brodeurtuition agencyWrite Stories Onlinesarasotarealestate Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
vbb
vbb

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.

Toby
Toby

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

kate
kate

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! :)

kate
kate

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 :)

Home Based Jobs
Home Based Jobs

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

Allen
Allen

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

sarasotarealestate
sarasotarealestate

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!

Write Stories Online
Write Stories Online

Thanks so much for that! I needed that :)

tuition agency
tuition agency

Been looking for helps regarding this for my wordpress blog.

Great tips.

Thanks a lot!

Carmen Brodeur
Carmen Brodeur

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.

digitalsolution
digitalsolution

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