Using wp_tag_cloud(‘format=array’) to print tag names without links?

I’m trying to pull just the tag names as an array collection in order to write them out as a simple listing, without links, but the array that’s returned does not send the name as an indexible item.

array(2) {
  [0]=> string(129) "<a href='#' class='tag-link-31' title='1 topic' style='font-size: 8pt;'>tag 1</a>"
  [1]=> string(127) "<a href='#' class='tag-link-30' title='1 topic' style='font-size: 8pt;'>tag 2</a>"
}

Is there another method I can use to get the entire site’s tag collection with just the tag names? This is my current code, but because of the array indexes, I get the links as well.

$tagNames = wp_tag_cloud('format=array');
echo implode($tagNames,", ");   

Related posts

Leave a Reply

2 comments

  1. try :

    function my_tag_list_123($sep){
        $tags = get_tags();
    
        foreach ($tags as $tag){
            $ret[]= $tag->name;
        }
        return implode($sep, $ret);
    }
    

    and call it when you need like this

    echo my_tag_list_123(',');
    

    hope this helps.

  2. <?php 
            $args = array(
            'smallest'                  => 12, 
            'largest'                   => 12,
            'unit'                      => 'pt', 
            'number'                    => 0,  
            'format'                    => 'array',
            'separator'                 => "",
            'orderby'                   => 'name', 
            'order'                     => 'ASC',
            'exclude'                   => null, 
            'include'                   => null, 
            'topic_count_text_callback' => default_topic_count_text,
            'link'                      => 'view', 
            'taxonomy'                  => 'post_tag', 
            'echo'                      => true,
            'child_of'                  => null, // see Note!
            );      
    
            $myCloud = wp_tag_cloud( $args );
    
            foreach ($myCloud as $tag) {
                $tag = strip_tags($tag);
                echo '<li>' . $tag . '</li>';
            }
        ?>