Support » Fixing WordPress » How to list categories, like wp_list_categories, but display also IDs?

  • Resolved webipsum

    (@ipsum)


    How to list categories (parents / children), like wp_list_categories, however, beyond the name, also display the ID?
    Tks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Try it with this in your theme’s functions.php :

    add_filter('list_cats', 'cats_with_id', 10, 2);
    function cats_with_id($category, $cat_list){
    if($cat_list)
      return $category . ' ' .$cat_list->term_id;
    else
      return $category;
    }

    keesiemeijer.
    It worked wonderfully.
    Thanks so much!

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    No problem, glad you got it resolved. I changed the code a little bit, so it’s only used on the front end of your website:

    if(!is_admin()){
    add_filter('list_cats', 'cats_with_id', 10, 2);
    }
    function cats_with_id($category, $cat_list = false){
    if($cat_list)
      return $category . ' ' .$cat_list->term_id;
    else
      return $category;
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to list categories, like wp_list_categories, but display also IDs?’ is closed to new replies.