This:
if (is_tag()){
will be true for any query on a tag archive page, including the query WordPress makes to load menu items.
You want to check if the current query is both the main query and tag query:
if ($query->is_main_query() && $query->is_tag()){
Related Posts:
- Which Template Page Should I Use?
- How can I create an automatic drop down menu with my tags?
- Custom Post Type Settings page, choose page to display archive
- Adding a menu item for a Custom Post Archive
- Adding custom post type archives to a WordPress menu
- How can I include custom post types on a tag page?
- Taxonomy count per Post type
- Now can I group custom post types together?
- How to add meta box to backend menu page
- post_tag taxonomy with custom post type
- Hide custom post type from nav menu manager
- Undefined property: stdClass::$labels in general-template.php post_type_archive_title()
- Menu with Automatic Pages Included from Custom Post Type
- Pagination problems with multiple custom post type archive pages
- Create Custom Post Type Archive Page with Sub Categories Navigation Sidebar
- Registering tags taxonomy for a custom post type
- Categories and Tags not working!
- Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page
- Adding Custom Taxonomy Archive Link to Nav Menu Shows Up As (Invalid)
- Why are navigation items saved in the database?
- How do I create an archive page for standard posts?
- WordPress custom post type archive with description
- CPT: archive-cpt.php VS custom page template
- ‘Pages’ widget alternative for custom post types?
- current-menu-item class for custom post type parent
- Rewrite URL for only archive page (custom post type)
- Archive slider for CPT
- Where to store custom tagging data associated with a custom post type
- Archive template for custom post type only lists first 10
- Should I use custom menu, C.P.T. or theme options, or something else for this?
- Function to display custom post type on front page makes menu items dissapear
- search also in taxonomy, tags and custom fields
- Listing tags from a custom post type
- wp_update_term_count_now doesn’t work with a custom post type?
- Add tag to a custom post type doesn’t change the total of custom post type in backend
- Second Set of Eyes: One custom taxonomy shows in Appearance > Menus, one does not
- Why is my site using index.php instead of archive?
- Custom post type archive page blank
- Is there a way to establish parent/child relationship in WP menu links exclusively?
- A page that shows a list of a specific custom post type
- How can I show 1 featured post in a styled element, and the next few below differently styled
- Review site custom post type structure
- Best way to specify “article type” in URL
- Including link to custom post type in ‘wp_list_pages’ function
- Creating tags via API
- Meta data (Tags and Categories) for Custom Posts not showing.
- Pagination doesn’t function properly for archive of a custom post type set as the front page
- Need help deciding on a taxonomy
- display custom taxonomies limited to custom post type?
- How to integrate single and archive templates for custom post type in any WordPress theme
- Get Posts by Category, Tag , and CPT Taxonomy
- WordPress admin display post type tags as checkbox
- The Difference Between Categories and Tags and Taxonomies and Terms
- Custom post type permalink uses archive page to display posts
- add custom tags for custom post type in wordpress
- Custom post type, taxonomy and admin bar
- highlight parent page menu item when in custom post type
- How do I override the default number of items to be listed on an archive.php page? [duplicate]
- Advanced archive url structure (category, tag and date)
- Tag template not returning posts [closed]
- Custom post type post in custom menu
- Custom post type posts wont show in wp_nav_menu()
- Best way for a plugin to define a custom post type archive template?
- Why doesnt my tag page populate with this custom post type?
- Home page is getting current-menu-item even if it’s not home
- How can I put content before my custom post type default pages?
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- get taxonomies from terms
- CPT tags not showing when editing post
- ACF Pro Accessing fields on a Custom Post Type
- wp_get_nav_menu_items doesn’t return custom post type item
- How to convert Post Object Custom Field into Tags
- How to add independent “Tags” to Custom Post Type?
- Automatically add CPT UI categories to the menu
- Possition a Custom Post Type Tab under Settings
- wp_nav_menu doesn’t seem to work on custom post type pages
- Iterating over custom post type archive returns incorrect first ID
- how to display notifications in the wordpress menu when a new post is published
- How do I make my archive page look like popular reviewing sites (e.g., Polygon and Gamespot) [closed]
- Get Non-Paginated Index of Post in Paginated Query
- Menu disappears with custom post type link
- Custom post tag images not displaying with ACF
- Use the page picker from wordpress menu creation page
- How to display custom post type in a submenu?
- Organizing The Custom Post Type with Taxonomies / Parent Posts
- add current-menu-item to multiple custom post types
- How to assign custom post template to its custom taxonomy terms
- Default taxonomy ‘post_tag’ added to CPT managing by custom role : nothing in the metabox
- Nav style for current page with custom post type
- Admin menu post type
- How to display the FAQ Archive page in my menu
- Custom Taxonomy Showing in WP Menu
- Plugins for putting Custom Post Types into the Menu
- No Current Class showing in Menu for Custom Post Types
- Custom post type in submenu with custom meta box as a title with custom html
- Getting (Invalid) when adding custom taxonomy of custom post type link in menu [closed]
- Tag-post relationship problem
- How to make a single Menu Item call another Mega Menu for Custom Post Types and Custom Taxonomies?
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Menu Structure and URL structure, with Pages and Post-Type-Posts