After googling around I found the correct way to do it by using the ‘wp’ hook
if (is_tax(‘term-country’))
add_action(‘wp’, ‘my_setcookie’);
// my_setcookie() set the cookie on the domain and directory WP is installed on
function my_setcookie(){
$path = parse_url(get_option(‘siteurl’), PHP_URL_PATH);
$host = parse_url(get_option(‘siteurl’), PHP_URL_HOST);
$expiry = strtotime(‘+1 month’);
setcookie(‘location’, ‘my_cookie_value_3’, $expiry, $path, $host);
}
Related Posts:
- Proper WP conditional tag to check for existing taxonomies to list out terms with wp_list_categories?
- Variable Not Working Inside is_author() Array
- Conditional if is single and part of the custom taxonomy
- Best Method to Switch Between Terms (Custom Taxonomy)
- Custom taxonomy terms not showing as list Gutenberg Editor
- How to only list the child terms of a taxonomy and not their parents?
- How to use taxonomies on attachments with the new Media Library?
- Hierarchical taxonomy UI
- Using pre_get_posts to rewrite search query to display posts from multiple taxonomies
- How to display custom taxonomies in posts?
- Filtering custom taxonomies
- Allowing specific users to only add posts using certain custom taxomy terms
- Edit tags page for hierarchical taxonomy doesn’t show taxonomies at all depths
- I want to load post content by categories using Ajax
- Hook to process a new taxonomy tag before it is created?
- Removing taxonomy base using WP rewrite
- get_terms() returns an empty array
- Scheduling posts to update once per day with wp_cron
- How to find taxonomy name using only taxonomy TERM ID (or taxonomy term name)
- Multiple users – only allow them to manage their own terms for custom taxonomy when logged in
- How to assign default taxonomy to pages on ‘save_post’?
- WP_insert_term how to insert multiple values as taxonomny term?
- Custom Taxonomy Images with Advanced Custom Fields
- Adding session variable and/or cookie based on user-selected input
- How to display term description in empty terms archive?
- How to Reverse Taxonomy Order
- get_terms custom order
- Check whether a custom taxonomy term has published posts?
- How to Query Database for posts with certain Taxonomy Term
- Check if term is in a taxonomy?
- Display direct children of the current custom taxonomy in taxonomy.php template
- How to show only terms by id or slug on edit-tags.php (custom taxonomy manage page) for a custom taxonomy
- Woocommerce: How to change the add to cart text in a certain category? [closed]
- get_term and get_term_by return null or false, even though term exists
- Can you filter wp_dropdown_categories with terms meta?
- one term two taxonomy’s?
- How do I modify the “Insert Media” lightbox in the admin to only show media items from a category?
- How to create pagination for custom taxonomy in WordPress
- Page and Post return 404 with custom taxonomy
- Order by taxonomy Value [duplicate]
- Retrieving an intersection of two terms from two different custom taxonomies via API
- Category list with indent children list below current category
- Some of my custom taxonomies are not showing but still counted in a WPMU set up
- Remove categories from post edit page, but keep in sidebar?
- How to set taxonomy hierarchical level to 2?
- Custom Taxonomy Not Working When added to WordPress Search
- Custom taxonomy terms in the admin site is not saving for widget
- Widget dropdown always displays first option
- How to get posts which must match both custom taxonomies?
- Display all taxonomy, children and grandchildren with links
- Using custom taxonomies to display hierarchical URLs?
- Passing form inputs into multi-taxonomy query
- Custom Taxonomy Tag Cloud?
- Taxonomy Parent Name
- Custom Taxonomy specific to a Custom Post type – rewrite URL
- Having Issue on Passing Variable into HTML Class Tag
- Copy/clone/associate Custom field to Custom Taxonomy
- How to check if post/page or taxonomy post is published by admin
- Load a certain functions file for a certain taxonomy
- tax_query: Don’t show posts with parent term when they have a corresponding child term applied
- Can’t get taxonomy ID for each post on archive page
- How do I get the labels from a post
- Hide custom taxonomy from easy admin
- Add file attachments/meta to a custom Taxonomy
- Displaying user selected custom tags/taxonomies on the front-end
- Why can’t I access Custom Taxonomy metadata?
- Permalinks with custom taxonomies and regular categories
- WP_Query tax_query – Show results if child has parent X
- Running a function only once when a taxonomy term is changed
- Taxonomy or Custom Field
- Trash Bin for Categories?
- Custom taxonomy – checking if name includes a declared value
- Display just the Post’s parent Category, not child
- Wp_insert_term doesn’t work from separate file with custom taxonomy
- How to add a shortcode function that returns the taxonomy slug of the actual post within the loop
- Random order not working correctly when using default loop + $query->set
- Convert post meta to custom taxonomy?
- How to create filter’s for custom taxonomy page
- How to get a taxonomy by a term slug?
- Get taxonomy link with post type slug prefix
- Query by multiple custom taxonomies
- get the custom taxonomy name?
- Modify title of custom taxonomy archive page
- qtranslate-x problem with custom term description
- WordPress custom taxonomies new/edit post autocomplete
- Templates files for custom post type with custom tags
- Custom Tax Archive of Parents Only?
- taxonomy query on front page
- Change taxonomy of posts
- Pagination with custom query (not using posts)
- Taxonomy Parameters in WP Query to get posts from two different taxonomies
- Update fields with post object and custom tax with wp_insert_post
- Get Posts with matching lowest taxonomies
- How to randomise a custom taxonomy tag cloud
- Any way to make custom taxonomy field searchable?
- query posts returns 10 records
- Select Custom Taxonomy from Theme Options
- Remove Tag Cloud Words from Custom Taxonomy
- add_rewrite_rule pagination 404 error on page 4 and above
- Hide empty categories on widget