1

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,", ");   
4

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.

| improve this answer | |
-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>';
        }
    ?>
| improve this answer | |
  • 2
    Please explain your code. Dumping of code like this without any explanation does not make a good answer and should be avoided. Please file an edit and add a proper explanation how your code works – Pieter Goosen Nov 3 '14 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.