marya marya - 1 year ago 79
PHP Question

Excluding specific multiple tags in the tag list in WordPress

I want to exclude 2 tags from the tag list in the following script:

$tags = get_tags();
$html = '<ul>';
foreach ( $tags as $tag ) {
if($tag->slug != "test1"){
$tag_link = get_tag_link( $tag->term_id );
$html .= "<li><a href='{$tag_link}' class='{$tag->slug}'>";
$html .= "{$tag->name}</a></li>";
$html .= '</ul>';
echo $html;

The script works correctly excluding
How do I edit the code in order to also exclude another tag named

Answer Source

As per DOCS:

'exclude' Default is an empty string. A comma- or space-delimited string of term ids to exclude from the return array. If 'include' is non-empty, 'exclude' is ignored.

You need to change 1,2 with tag ids of test1 & test2.

$args = array('exclude' => '1,2' );
$tags = get_tags($args);
// .... Rest of your code goes here

Don't forget to remove if check if($tag->slug != "test1"){ as it would be useless with exclude in $args :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download