preload

WordPress Tip: Get Current Category Name

A quick way to get the current category in your WordPress blog is by using this code:


foreach((get_the_category()) as $cat) {
      $nameOfCategory = $cat->cat_name;
}

This small script will help you to exclude certain blog posts from showing on certain main categories. It was a life saver when developing the Olympus-Tours blog.

Leave a Reply

* Required
** Your Email is never shared