By Stephen Walker
Share
If you work with numerous non-published posts, it might be helpful to show the status. This shortcode shows the status if the status is currently not “Publish.”
function current_post_status_shortcode($atts) {
global $post;
// Check if we are inside a post
if (!isset($post->ID)) {
return '';
}
// Get the post status
$status = get_post_status($post->ID);
// Check the post status
if($status != 'publish') {
return $status;
}
// If post status is 'publish', we return an empty string
return '';
}
add_shortcode('post_status', 'current_post_status_shortcode');
Originally published on July 20, 2023