Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all existing tags outside the loop in Wordpress

Here is my situation.

In my home page, I want to have the list of all existing tags and use them as filter for an isotope grid containing posts.

So for each post I already check the associated tags and output them as class name on the post grid-item for filtering.

I have an hard time getting the list of all my existing tags. I think it should be easy stuff to do. What am I missing?

like image 858
user3211188 Avatar asked Sep 16 '25 17:09

user3211188


1 Answers

This is an example:

$tags = get_tags();
$html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
    $tag_link = get_tag_link( $tag->term_id );

    $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
    $html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;

Example taken from here: https://codex.wordpress.org/Function_Reference/get_tags

like image 200
muka.gergely Avatar answered Sep 18 '25 10:09

muka.gergely