Add Published Post Count After WP Nav Menu Items

This code, once added to your child themes functions file, displays the post count in your nav menu.

Every time you publish a new post, it dynamically updates and also changes if you delete a published post.

You can change the primary in the code to secondary or any other nav menu location.

You can also change the text to anything you like and modify the functions parameters.

You could also replace the last-child structural pseudo-class with last-of-type.

The only issue you may have is with the CSS class your theme uses.

Based on testing the code in different themes, i found the best way to work out which class to use is to inspect the output and try the different classes your theme generates.

Related Code

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.