Support » Developing with WordPress » Is there a function to list all post tags?

  • Resolved shemakeswebsites

    (@shemakeswebsites)


    Hello, I am using this shortcode to output a list of all the post categories onto a page. Is there a way to do the same with post tags? I’ve tried a few things but haven’t had luck and it seems the codex just offers the tags for the current post:

    function show_categories_pg(){
      return wp_list_categories("echo=0&title_li");
    }
    add_shortcode('show_categories', 'show_categories_pg');
Viewing 5 replies - 1 through 5 (of 5 total)
  • That same function can list any taxonomy.
    https://developer.wordpress.org/reference/functions/wp_list_categories/

    The name of the standard Tag taxonomy is post_tag.

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    Thanks for your help again Joy. I think I need to build arrays into my code to get the post tags, but I’m getting errors when trying to do that. I guess the samples that are shown are used in templates, but not in the form of a shortcode snippet so it’s just not working out. I’ll keep trying.

    Thanks Steve, this tells me how to get the tag list from the current post, so it’s shown in the loop. I’m trying to output all the tags from all posts onto another page, like an index.

    Thanks to you both.

    Create a new shortcode for tags

    function show_tags_pg(){
      return wp_list_categories("echo=0&title_li&taxonomy=post_tag");
    }
    add_shortcode('show_tags', 'show_tags_pg');

    Or add parameters to the original shortcode

    function show_categories_pg($atts) {
      $supported = array( 'echo' => 0, 'title_li' => '', 'taxonomy' => 'category' );
      $args = shortcode_atts( $supported, $atts );
      return wp_list_categories($args);
    }
    add_shortcode('show_categories', 'show_categories_pg');

    Thank you very much. I wouldn’t have been able to figure this out. The second snippet is quite handy too, I can now also add a product category/tags index as well. Much appreciated. 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.