One Sticky Post in Wordpress

WARNING: This article features ANCIENT code! I'm keeping it online because it's interesting to see what I was thinking 10+ years ago. But you DEFINITELY should not be using this code. Anything you're reading about on this page has changed significantly since this was written.

As of Wordpress 2.7, there's a nice little feature called "Sticky Posts" that lets you specify that a particular post should be pulled out of its regular position in reverse-chronological order and placed at the top. It's a great way to draw attention to a particular post or give it special styling.

One tiny downside is that when you add a new sticky post, you also need to go remove the old ones. That's perfectly fine if you want several sticky posts on your site, but for my purposes, I only wanted one sticky post at a time.

So here's a quick function that automatically unsets old sticky posts so you never have more than one at a time. You can add this directly to your functions.php file or wrap it in a plugin. As always, use at your own risk.

add_action( 'admin_init',  'ct_sticky_admin_init' );
function ct_sticky_admin_init() {
    add_action( 'save_post', 'ct_sticky_save_post' );
function ct_sticky_save_post( $post_id ) {
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    $sticky = isset($_POST['sticky']) && $_POST['sticky'] == 'sticky';
    if( $sticky ) {
        $sticky_posts = array($post_id);
        update_option('sticky_posts', $sticky_posts);