Colour-Coding Posts Based on Status

I can’t take full credit for the below code. I found this snippit online somewhere and can’t remember the source! But it’s something I’ve been using for a while and I absolutely love it, so I thought I’d share. 🙂

Requirements

  • Must be using a self-hosted WordPress blogging platform.
  • Must be able to edit your functions.php theme file (or create a new one if one does not already exist).
  • Coding knowledge is a plus, but is not required, as you can simply copy and paste the code.

What We’ll Be Creating

As a WordPress blogger, you probably have a lot of published posts, a few draft posts, a few scheduled posts, and maybe even private posts! I find it really helpful to more clearly differentiate between them on the “All Posts” page. So let’s colour code them!

When we’re done, your All Posts page will look something like this:

Colour Coding Posts Based on Status

The green ones are scheduled posts, the red are drafts, and the normal (white) ones are published posts!

The Code

First you have to locate and edit your functions.php file. If you don’t have one, you’ll have to create a new one. Your file should look something like this:

<?php

//Lots of code here

?>

The important thing is that it starts and ends with those php tags. The code below assumes you have those php tags included. If you don’t, you’ll have to add them in before and after the code.

Now copy the below code and paste it in your functions.php file:

/**
 * Add Colour Codes
 *
 * @since 1.0
 * @return void
 */
function ng_colour_code_post_status() {
	?>
	<style>
		.status-draft {
			background: #fad8d8 !important;
		}

		.status-future {
			background: #CCFF99 !important;
		}

		.status-pending {
			background: #FFFF99 !important;
		}

		.status-private {
			background: #FFCC99;
		}
	</style>
	<?php
}

add_action( 'admin_head', 'ng_colour_code_post_status' );

You can of course change the colours to different hex values to suit your own preference. I personally have it set up so that drafts show up red, scheduled posts show up green, and published posts show up how they normally would (no different background).

I hope you find this useful! I personally think it’s so much easier to take a quick glance and know immediately what’s what!

Want the plugin version of this?

I’ve packed this code into a plugin in case you just want something you can quickly install. Download it using the link below, then upload the zip file into Plugins > Add New > Upload.

Photo of Ashley
I'm a 28 year old California girl living in England (I fell in love with a Brit!). My three great passions are: books, coding, and fitness. more »

Don't miss my next post!

Sign up to get my blog posts sent directly to your inbox (plus exclusive store discounts!).

You might like these

16 comments

    1. I hope you can get it working! Let me know if you have any trouble – I’d love to help. 🙂

    1. Yep that’s absolutely possible! Instead of this:

      .status-draft{background:#fad8d8 !important;}

      Change it to something like this:

      .category-book-reviews{background:#fad8d8 !important;}

      And you can add different lines for each category. Note that the class you have to put in will be the *slug* of your category. That means dashes instead of spaces and all lowercase!

      1. Is it possible to do this with the colors for categories but still keep the color for the drafts? So if I want my reviews to be blue but my drafts to be red, then a review draft could be red until it was published and then it would turn blue?

        1. Yeah it should be. You’d put the category code first, then draft. So like this:

          .category-book-reviews{background:#fad8d8 !important;}
          .status-draft{background:#fad8d8 !important;}

  1. I couldn’t figure out why this wasn’t working, until I realized that all my posts were published lol!

    Thanks for all the amazing tutorials and your plugins and themes! You are awesome! I don’t know how I blogged without all this for years!

    1. Haha!

      It’s my pleasure! Honestly this is one of my favourite snippets. I can’t imagine blogging without this. I feel like my admin archive of blog posts would be a complete mess without the colour coding.

  2. Been using this and loving it, but updating to WordPress 3.7 broke it and when I try to just redo it with the same directions, it doesn’t do anything. Any hope for a fix for it? Or maybe you might know what broke it? The last two wordpress updates didn’t effect it. I don’t know what it is about 3.7.

    1. I’m using the exact same code here on my blog and it works just fine for me. :/ (Both before and after the WP 3.7 update.)

Recent Posts

    Random Posts