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”
- Can’t set a cookie from php
- How to say if meta_value is greater than 0 in an array?
- Getting users with a specific meta data and then querying their posts?
- Why does the post_type_link hook everything twice?
- Adding a tag_ID column into Categories inside the admin dashboard?
- How to pass a variable into an add_filter() function?
- locale filter function running multiple times
- Multiple requests external data api dynamic block gutenberg
- Why does the Woocommerce grouped template prints the unpublished products?
- Woocommerce with Lazy Load php and ajax
- Adding conditional text to a PHP Shortcode Template
- How do I get the content excerpt of the recent post?
- How to check $_GET isset for a parameter and value? [closed]
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- Making your own custom post views count
- Save Custom CSS file in the upload folder dynamically?
- How to use two meta_compare in an array?
- How to update and save user metadata on page visits?
- Verify if a category is the child of another category
- How to remap one of the TinyMCE Advanced Editor button to open the wordpress media library?
- Simple AJAX notification when the new post is added to the database
- How to optimize update_post_meta?
- Warning: in_array() null given in PHP function
- Contact Form 7 – Replace database configured form template with a static file
- AJAX wp_insert_user WORKS but responds with “The site is not enabled”
- Why can’t I return a value from $wpdb->get var?
- How to get User Time Zone in WordPress?
- How to hook a logout funtion for specific usr role in wordpress?
- Redirection after submitting duplicate comment
- Convert code – not work
- Fix error Gravatar alt
- HTML Special Characters in URL string [closed]
- how to save checkbox data for custom setting?
- How to remove sidebar primary widget on Mobile on category page [closed]
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- Upload multiple files in randomly generated folder using wp_upload_bits
- Is it possible to change content in my PHP file from WordPress dashboard
- ACF put a comma after the last repeater field value [closed]
- Create page template via functions.php?
- Loading two post layouts for the same post with different url
- Code snippet to show current php version inside “At a Glance” box in admin
- parsing nested blocks (in columns, etc) via PHP
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- getting url from variable that calls picture of current page, not working. Only displays everything instead of url
- How to upload WP user avatar on woocommerce account page [closed]
- Use post ID in functions.php file adminside
- How to show childs of certain custom post type in option list?
- Short code template + ajax
- str_replace with the_content is not working
- How do I populate custom field with current user role in Woocommerce [closed]
- WPML best page selector with php
- How to disable send e-mail notification new comments for some posts
- trying to put an active hover to my custom nav category buttons [closed]
- How to edit HTML of my website on WordPress? [closed]
- Redirect first comment (Thanks for comment) with show Autor name and beginning of the comment
- Large WordPress CRON job
- Fixing Deprecated: get_the_author_lastname
- WordPress query undefined offset in loop
- Referencing Images in javascript to display on wordpress page