X

How to Highlight Your Post Status in WordPress

Snippets by IsItWP

Do you want to highlight your post status on your WordPress dashboard? The status of a given post, such as Published, Draft, Pending, etc. determines how WordPress handles that post. Let’s take a look at how to highlight post status within admin posts and pages.

highlight post states within admin posts and pages

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

function custom_post_states( $post_states ) {
   foreach ( $post_states as &$state ){
   $state = '<span class="'.strtolower( $state ).' states">' . str_replace( ' ', '-', $state ) . '</span>';
   }
   return $post_states;
}
add_filter( 'display_post_states', 'custom_post_states' );

function custom_post_states_css(){
	echo '<style>
		.post-state .states{
			font-size:10px;
			padding:3px 8px 3px 8px;
			-moz-border-radius:2px;
			-webkit-border-radius:2px;
			border-radius:2px;
			}
		.post-state .password{background:#000;color:#fff;}
		.post-state .pending{background:#83CF21 !important;color:#fff;}
		.post-state .private{background:#E0A21B;color:#fff;}
		.post-state .draft{background:#006699;color:#fff;}
	      </style>';
}
add_action('admin_head','custom_post_states_css');

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes or 7 best WordPress contact form plugins.

Comments  Leave a Reply

  1. Thanks for this. It should make a good companion to the (now updated) custom statuses snippet.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[60% OFF Today!]
[60% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]