0

I've been trying to echo some text to all single pages that are part of tag_ID 129

This is the code that I used

<?php 

if ( is_tag( '129' )){

echo '<p> test 2</p>';
    }
?>

so far no luck.. The image attached is too show where I'm getting the info

any help would be great! thanks

https://wpengine.com/wp-admin/term.php?taxonomy=ait-items&tag_ID=129&post_type=ait-item&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dait-items%26post_type%3Dait-item

enter image description here

1

That's not what is_tag does:

Determines whether the query is for an existing tag archive page.

https://developer.wordpress.org/reference/functions/is_tag/

is_tag and other functions such as is_search etc don't tell you anything about a post, they tell you if you're on a search archive, or a tag archive, etc

So is_tag is true on example.com/tag/example but would be false on a post because that's not a tag archive.

Instead what you want, is has_tag https://developer.wordpress.org/reference/functions/has_tag/

Some final notes though:

  • Don't hardcode term IDs! Use the slug/name if you really have to hardcode things. If you ever delete that tag by accident, or have to do a migration, your code would stop working.
  • Indent your code, it'll avoid entire types of bugs, and make it easier to read ( especially for people who might answer questions :p )
  • If in doubt, check the official docs at https://developer.wordpress.org/

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.