Do you want to add custom status message for each post that an author creates? While there’s probably a plugin for this, we have created a quick code snippet that you can use to create custom post status message in admin in WordPress.

Instructions:

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

Only users with the publish_posts capability can change the status while everyone sees what the status is (if it is set). You can remove the status notification by selecting none.

add_filter( 'display_post_states', 'custom_post_state' ); function custom_post_state( $states ) { global $post; $show_custom_state = get_post_meta( $post->ID, '_status' ); // We are using "None" as a way to disable this feature for the current post. if ( $show_custom_state && $show_custom_state[0] != 'None' ) $states[] = '<span class="custom_state ' . strtolower( $show_custom_state[0] ) . '">' . $show_custom_state[0] . '</span>'; return $states; } add_action( 'admin_head', 'status_css' ); function status_css() { echo ' <!-- Styling of Custom Statuses --> <style type="text/css"> .custom{border-top:solid 1px #e5e5e5;} .custom_state{ font-size:9px; color:#666; background:#e5e5e5; padding:3px 6px 3px 6px; -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; border-radius:3px; } .spelling{background:#4BC8EB;color:#fff;} .review{background:#CB4BEB;color:#fff;} .errors{background:#FF0000;color:#fff;} .source{background:#D7E01F;color:#333;} .rejected{background:#000000;color:#fff;} .final{background:#DE9414;color:#333;} </style>'; } // Only those with the capability should be able to change things. if ( current_user_can( 'publish_posts' ) ) { // Insert our "Custom Status" into the Post Publish Box add_action( 'post_submitbox_misc_actions', 'custom_status_metabox' ); function custom_status_metabox() { global $post; $custom = get_post_custom( $post->ID ); $status = $custom["_status"][0]; $i = 0; // Available Statuses $custom_status = array( 'None', 'Spelling', 'Review', 'Errors', 'Source', 'Rejected', 'Final' ); echo ' <div class="misc-pub-section custom">Custom status: <select name="ourstatus">'; for ( $i = 0; $i < count( $custom_status ); $i++ ) { echo '<option value="' . $custom_status[$i] . '"'; if ( $status == $custom_status[$i] ) echo ' selected="selected"'; echo '>' . $custom_status[$i] . '</option>'; } echo '</select></div>'; } // Save add_action( 'save_post', 'save_status' ); function save_status( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; update_post_meta( $post_id, "_status", $_POST["ourstatus"] ); } }

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add 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: How to create stunning WordPress optin forms and 10 best WordPress testimonial plugins.