On the page where you want to set the cookie
write this code and check
if(get_query_var('my_var') == 'somevalue'){
setcookie('my_cookie', get_query_var('my_var'), strtotime('+1 day'));
}
If we go with your code then it will set coookie
on every page who having query variable
?my_var=somevalue
Related Posts:
- What is PHPSESSID?
- Setting custom cookies in WordPress
- How to set custom cookies before output
- Check if user already visited this post today
- Display message once per session to users with a specific role
- Using Cookie Data For WP_Query Loop
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- How to resolve error “Cookies are blocked due to unexpected output.”?
- Using a nonce in a Custom Login Form
- How to sanitize my cookie name
- Setting a cookie upon specific URL visit
- How to Highlight unread WordPress posts?
- Why is my cookie not unsetting upon logout? [closed]
- How to combine wordpress_logged_in cookies in one cookie?
- How to store post ID’s in cookie or session to display the same posts later
- how can i use $_COOKIE[] + PostID to execute the below code?
- iframe does not store session/cookie when refresh parent
- Insert custom PHP head above in WP pages
- My php code is not being executed
- $_SESSION variable not saving on page refresh or new page
- How to set cookies
- How to make a cookie be on the whole site instead of being on a specific page/
- Set cookie for visitor
- Authentication from sub-folder non-wp cookie WordPress
- setcookies and header send
- Triggering a timewall after X days
- Set cookie parameters on wp site – PHP not working?
- Fatal error login WordPress [duplicate]
- IF statement not working – Any suggestions?
- Use WP user status (logged_in) to manage access to independent application
- WordPress load javascript file if something… (after the page is loaded)
- Serve cookie free URLs in WordPress without using a CDN
- Allow user to select location and then set cookie for location in WordPress
- Use WP_Query Data In Cookie
- Create and update Custom Cookie based on multiple GET and POST Values for first time visitors?
- Cookie not created in AJAX request
- Why can’t I enter the wordpress admin interface?
- Losing Session ID and sessionStorage when navigating to other domains on Multisite
- Keep users logged in Without Remember Me
- Why can’t I enter the wordpress admin interface?
- I can’t log into my website , it says “Error: Cookies are blocked due to unexpected output”
- Mega Menu Walker
- How to add a class to the attachment images
- Why would a GET variable one one page of a site cause a 404 error when a GET variable works on another page of a site?
- Why can I not use setup_postdata($post) in the sidebar?
- Activate different theme for temporary preview
- Get WooCommerce shipping methods programmatically
- Add a custom text field to WooCommerce admin product data “Variations”
- How do I output a database option that is an array into a get_posts array?
- Passing jQuery value using Ajax to a page template
- Change logo based on incoming domain
- Creating login session via CURL
- WordPress vs. Custom PHP [closed]
- Trouble With Conditional Logic in PHP
- Remove meta description on certain pages
- Image media upload metabox
- Author Tracking Code!
- Is there CSS to expand the gallery limit on Index Pages?
- Hide categories that are not used in the post type
- Limit 1 global comment per minute
- How can I add an area/option for a custom page description?
- Is there a way to conditionally check whether a WordPress post title is empty?
- Advanced Custom Fields – display label and value only if value entered
- Use WordPress function in php file
- How to parse multiple links from one variable?
- $wpdb returns duplicate posts
- How Can I Edit the Registration Code?
- load more button in plugin
- Display attribute on shop page after the title
- Cant connect to database with php 7.3
- WordPress WP_Query without query GET parameters
- How to clone all WordPress Rest API end points
- Controlling image output size ACF repeater [closed]
- Initial offset of number of posts in home page on the posts page
- Run JS Code on userlog out
- display specific widget to a page
- How to set base url for php widget
- Remove the Tag from wp_nav_menu
- Time Delay a URL Redirect for Specific Page
- Sort column in Users admin Tab
- jquery & ajax getting data from php in wordpress . admin-ajax.php returns 400
- image uploader for widget
- use php variable in wordpress page
- How do I track which user clicked my button?
- Access WP files on “server 1”, from “server 2” – using wp-load on an external website
- Run htmlentities() on all submitted values through gravity forms
- How to change query string with pretty URL in WordPress using .htaccess file
- I want different post-thumbnail size depending on media size
- Submitting my form to the database and then redirecting to payment site
- Pass the updated value of aid from form using ajax
- Remove all nav menu classes except those which begin with certain letters
- featured post as div background
- Combining fancybox with multiple thumbnail plugin
- How to display thumbnail if post is assigned one otherwise not
- Highlight posts currently being edited on multiple editor site?
- How to check “From Email” via WordPress before an email is sent
- WordPress Plugin Receive a Link
- Php echo into tag
- Remove Unused Menu Locations
- Correct way to perform a GET to another PHP file hosted on wordpress