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/