Wordpress: Get current category ID and name

/ Published in: PHP
Save to your folder(s)

Copy this code and paste it in your HTML
  1. <?php if (is_category()) {
  2. global $wp_query;
  3. $cat_obj = $wp_query->get_queried_object();
  4. echo $cat_obj->name . " has id ". $cat_obj->term_id;
  5. } ?>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.