wp-content » themes » functions.php » Display the Total 🔢 Number of Posts in WordPress

Display the Total 🔢 Number of Posts in WordPress

Step 1. Add the following inside your theme functions.php file or create a new Child theme first and add the code to it:

function post_count() {
    $total = wp_count_posts()->publish;
    return $total;
}

add_shortcode('total_posts','post_count');

Step 2. Add the shortcode [total_posts] anywhere on the website where you want to display the total number of posts:

image 16 - Display the Total 🔢 Number of Posts in WordPress

And it will display the number. 🙂

See also  How to get WordPress image link from the media ID

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended