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

Display Open or Closed
Human Readable Time

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

RELATED Snippets

  • ChatGPT, PHP

    I prefer to have my dates in human-readable time difference or AP style dates, so this function will replace the default date format and output either the human-readable time difference or if the date difference is more than 180 days, the AP Style date.

  • ChatGPT, PHP, Shortcode

    WordPress has a great function built-in to express the date posted in a more readable format.

  • ChatGPT, PHP, Shortcode

    I used ChatGPT to generate a shortcode that would indicate whether a business is opened or closed.

  • Advanced Custom Fields (ACF), PHP, Plugins

    Since ACF turns off the WordPress custom fields, this snippet will bring them back. Just add it to your functions.php or your favorite code manager

  • PHP, Shortcode

    I wanted to show the date the article was posted and the date updated if the dates differ. This shortcode will do just that.

  • PHP, Shortcode

    I needed a way to get the first letter of the post title without requiring a custom field. An example of its use can be seen on the First Initial Post Card.