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/
Related Posts:
- Is There a Difference Between Taxonomies and Categories?
- Can’t custom taxonomies have same terms (slugs) as categories?
- How to display non-hierarchical taxonomy as terms with checkboxes?
- get_categories for custom post type with a specific custom taxonomy attached
- Control term order on a per-post basis
- How can I add the featured image functionality to a custom taxonomy?
- Combine two taxonomies in a hierarchical tree
- Use tag interface for hierarchical taxonomy?
- How can I select a primary category?
- Using URL parameters, list posts from category and custom taxonomy
- How to make custom taxonomy check boxes like ‘Categories’
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- How to create non-unique sub-category slugs?
- How to get next previous category in same taxonomy?
- Getting WordPress custom taxonomy/category?
- Display empty taxonomy terms with get_terms()
- How to get the number of child categories a specific parent category has?
- How can I convert some categories to a custom taxonomy?
- Any way to assign Post Categories and Tags to Links?
- Get multidimensional array that reflects category hierarchy
- Search Posts / Pages with multiple options?
- Change existing taxonomy settings when using custom taxonomy
- How to get the id from the custom category?
- How to “group” (categorize) the Pages together?
- Is There a Difference Between Taxonomies and Categories?
- How can I edit the ‘Most Used’ tab in the categories meta-box to show another custom taxonomy?
- How can I hide tags on a child-category page, if that tag has not been used?
- Display custom taxonomy attached to the post on post single page
- Question on using custom structures for categories
- Is there a reason I cannot get the current category in a loop?
- Same menu for different taxonomies to reach different content
- Conditional category & tag statement
- How could I write a get_categories_by_year() function?
- How to get posts using category slug in ClassiPress?
- Automatically adding tags and categories into Post Excerpt for searching
- How to set the same base url for two different taxonomies?
- Filtering posts in category by tag URL
- Get WooCommerce product category list in functions.php
- Using heirarchial tags or Custom taxonomies
- How to assign Categories and tags inside the TinyMCE Editor for each Image?
- Why use hierarchical taxonomies instead of many custom taxonomies?
- Renaming default category taxonomy?
- How to echo Tags and Categories as plain text
- How to Manage and link certain custom taxonomy?
- Display List of Categories Within a Custom Taxonomy
- How to exclude category and post_tag taxonomy while displaying custom taxonomy?
- How to add a post with new Taxonomy without assigning to default category?
- Converting Categories (with ACF fields) to custom taxonomies
- How can I get the categories and subcategories separately?
- Order get_terms() By Custom Field
- How do the ‘tag’ and ‘category’ (default) taxonomies do ‘save_post’ action?
- Sort posts by tags in category pages
- Is it possible to disable certain user roles from creating tags?
- what is the action hook code to supporting product category condition in single product page of woocommerce?
- Conditional Tag for sub cagtegories?
- Are Custom Taxonomy Templates Possible?
- Remove Categories and Tags from Admin Dashboard
- What’s the difference between “parent” and “category_parent” in a WP_Term object?
- Hide tag and category boxes from the post editor
- conditional statement for custom taxonomy
- PHP Fatal error: Cannot use object of type WP_REST_Response as array in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
- How to know if it’s a child taxonomy?
- Categories: A Greenhorn Question on Strategy (Not Code)
- Show Available Taxonomy List with Current Category
- Exclude a category from the_category in the single post page
- Why does the argument list_only do on Walker_Category_Checklist::start_el?
- Pagination is not working properly in Product Category/Tag pages
- add_rewrite_endpoint returns 404 on archives
- Get Number of total Parent Categories for Custom Taxonomy
- Create custom taxonomy and Display in metabox dropdown
- Limit categories and it’s subcategories for specific group of users
- Ive got a term (get_term_by) but now I want to filter it by a category it is in?
- Admin: Navigation Menus do not show empty categories/taxonomies in the list’s search tab
- Trying to add taxonomy to get_categories() but it’s not working. How to fix this?
- Proper WP conditional tag to check for existing taxonomies to list out terms with wp_list_categories?
- Need help deciding on a taxonomy
- Get Posts by Category, Tag , and CPT Taxonomy
- Having a template per category? Bad for server overhead?
- WP 4.7 in_category change?
- Illegal string offset ‘taxonomy’ in
- Let user select their own category
- How to store category and tags separatly on wordpress?
- Advanced archive url structure (category, tag and date)
- 3.1 post formats and specific categories/custom taxonomies
- sidebar troubles, taxonomy trouble
- WordPress Default Category and Custom Taxonomy Selected Attribute not Working After Searched in wp_dropdown_categories Array
- How to show related posts of category on post within custom posttype
- Multiple Tag Filtering
- Automatically create tags and merge with categories
- ACF Custom field not showing in Timber Taxonomy page
- Confused about category.php template – not working
- Limit Category/Tag Dropdown To blog_id in Multisite Install With Global Categories/Tags
- How to add an “All” category to the tag cloud?
- Display Taxonomies in loop with template args
- Display only the latest post
- get IDs from links categories
- Multiple Parent Category URLs
- Taxonomy term RestApi data 10 rows limitions
- Category and tags are not working properly
- Error while add Category or Tag in WordPress