Home / admin / highlight post_states within admin posts and pages
  • How to highlight post_states within admin posts and pages


    Adding this snippet to the functions.php of your wordpress theme will highlight the posts_states within the admin post and page sections.

    ( example screenshot ) ( click code to copy )

    wordpress snippet : PHP

    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{
    			padding:3px 8px 3px 8px;
    		.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;}

    ( WordPress codex functions, hooks, in this snippet. )

    admin_head, add_filter, add_action, wp,
  • Drew Jaynes

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