Just check if the variable is set, using the code from your link:
add_action( 'init', 'set_agent_cookie' );
function set_agent_cookie() {
if (isset($_GET['code'])) {
$name="agent";
$id = $_GET['code'];
setcookie( $name, $id, time() + 3600, "https://wordpress.stackexchange.com/", COOKIE_DOMAIN );
}
}
Related Posts:
- Setting Cookie Using a Variable from the URL
- How to pass post title (which could include &) to Gravity Form
- Error: “Cannot modify the return value” c#
- Python conditional assignment operator
- C++ identifier is undefined
- What is the PHP syntax to check “is not null” or an empty string?
- ISO C90 forbids mixed declarations and code in C
- Which variable size to use (db, dw, dd) with x86 assembly?
- Why SQL Server throws Arithmetic overflow error converting int to data type numeric?
- Character constant too long for its type
- What is the meaning of @_ in Perl?
- What is the meaning of @_ in Perl?
- Passing a variable to get_template_part
- What are all the Properties of the WordPress Post Object?
- Passing variables from header.php to template and vice verca
- When to use global $post and other global variables?
- WordPress variables and memory
- How to create custom variables in the wp-config
- {{ Double Curly Brace }} data.____ Variable Source in WP_Playlist Template
- What is the best way to store custom variables
- Get restrict content by submitting Gravity Forms
- WordPress filtering utm_ GET variables from url unless logged in as admin, not sure why?
- Using variable in two functions
- What is the $current_screen global variable?
- Gravity Forms skip form if already filled out using cookie?
- Print string to footer using wp_footer option
- How to pass data around?
- How do I pass variables into short-code enabled Post Snippets in WordPress 3.0?
- Replacing string with a variable in php
- Why does a variable work on the front page but return NULL on all other pages?
- Unset a Cookie on Successful Gravity Forms form Submission [closed]
- Variable scope producing undefined variable notices in included files
- Use to track referrals
- Can you keep session data for visitors?
- Changing static text in a theme into variable content that also respects language. Easiest way
- Result of API Request to global variable?
- Shortcodes — Using add_action, add_filter in the shortcode
- Setting Cookies For Form Autofill
- Best way to pass variables around a WordPress site?
- How do I share variables between two functions?
- What is the use of $content_width?
- Passing a variable from a FOREACH loop in a link
- What does the Global Variable $s represent?
- Get current page id, title, url, etc
- keep a variable for all pages in memory from the url
- Retrieve custom variable
- Pushing Category and Publish Date to Google Analytics
- Trying to create an edit page link?
- Cron Job variable not accessible
- No access to global variables?
- How to access a variable on all page?
- Not passing correct value to get_post_ancestors?
- Help me edit a variable with php
- SFTP define in wp-config.php
- What’s the best way to echo out a filter variable?
- Preventing Duplicating Posts from Widgets
- saving variables after redirect
- Redirect users in first login to a dynamic link
- WP CLI – Pass Query / URL Variable to Cron?
- Use a select box to change a php variable
- Can’t access a variable defined in another template despite using GLOBAL
- How to pass a variable for key/value pairs in an argument?
- Where and how to define variables for URLs etc
- How to get variable from function.php to loop file
- Setting a cookie in functions.php and it gets deleted when working on an other function
- Pass variable to next page
- passing javascript variable into php wordpress
- Remove # from a Variable [closed]
- Create and update Custom Cookie based on multiple GET and POST Values for first time visitors?
- Variables posting twice
- Passing variables trough 2 pages
- update_option using variable name
- assign the returned value of wordpress function to a variable?
- Pass var into wp function instead of direct string text
- How do I echo saved data outside the function?
- Having problems accessing $_GET values
- How to pass variable to functions.php?
- Creating a Variable Product
- How to set and retrieve cookies while in the loop
- how to define variable in jquery
- What is the purpose of having a token in cookies?
- gform_after_submission content appears immediately after , not in post body [closed]
- Rest API authentication issue when called from fetch request in bundle.js
- Logout user and delete cookies from the client side?
- Gravity forms – Can I have multiple custom spinners? [closed]
- Using file_get_contents with Gravity Forms uploads folder to create images in the media library returning false
- Why a strange discrepency between get_current_user_id() when using AJAX versus output of document.cookie?
- Gravity Forms Webhooks [closed]
- Declaring in variables [closed]
- WooCommerce Custom Product Validation [closed]
- How to pass variables from a function in functions.php to an other one
- How to Collect Keyword and Search Engine Data on Webforms?
- Displaying content based on drop-down menu selection sitewide
- Gravity Forms returns to odd position
- Gravity Form Repeater File/Media Upload Not Working
- How to check a variable Changes
- How are sites using wordpress hiding wordpress cookies that have “wp” or “wordpress” in the cookie name?
- Populate a drop down list with post titles across a multisite network
- How do I access variables outside a function [closed]
- How to remove without touching the pluggable.php the wordpress_logged_in cookie to show the username on login?