get_tags( string|array $args = '' )

Retrieves all post tags.


Description Description


Parameters Parameters

$args

(string|array) (Optional) Tag arguments to use when retrieving tags.

Default value: ''


Top ↑

Return Return

(array) List of tags.


Top ↑

Source Source

File: wp-includes/category.php

function get_tags( $args = '' ) {
	$tags = get_terms( 'post_tag', $args );

	if ( empty( $tags ) ) {
		$return = array();
		return $return;
	}

	/**
	 * Filters the array of term objects returned for the 'post_tag' taxonomy.
	 *
	 * @since 2.3.0
	 *
	 * @param array $tags Array of 'post_tag' term objects.
	 * @param array $args An array of arguments. @see get_terms()
	 */
	$tags = apply_filters( 'get_tags', $tags, $args );
	return $tags;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.3.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex

    Displays a list of tags with links to each one and a specific class for each tag:

    $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;
    
  2. Skip to note content
    Contributed by Rubel Miah

    Display all tags in list format with links.

    $tags = get_tags(array('get'=>'all'));
    	$output .= '<ul class="tag-cloud-list">';
    		if($tags) {
    		foreach ($tags as $tag):
    		$output .= '<li><a href="'. get_term_link($tag).'">'. $tag->name .'</a></li>';
    		endforeach;
    		} else {
    		_e('No tags created.', 'text-domain');
    		}
    	$output .= '</ul>';
    return $output;

You must log in before being able to contribute a note or feedback.