Cookie Monster – WordPress URL Parameter Utility
I recently had a situation in which I needed to pass a URL parameter into WordPress so that it could be inserted into all links off of a blog page. For example, a partner would pass traffic to a blog using the format http://www.myblog.com?refcode=joe. All links embedded in the post would need to pass the value of refcode if it existed, even if the visitor requested multiple pages after the initial visit.
I created a Plugin (Cookie Monster) that will allow a Blog Admin to define which URL parameters should be captured, and then creates a shortcode so that the value can be used in your Posts and Pages. A WordPress shortcode is a macro code that is embedded in your content.
In the example above, if you define refcode in the Cookie Monster Admin Settings, and if that URL parameter refcode contains a value in the querystring, it will automatically be saved into a cookie in the visitors browser. Anywhere that you place the shortcode [refcode] in your Post, Cookie Monster will insert the querystring value into your Post. The cookie value will persist across browser sessions.
If you click on this link, you will see that the querystring value refcode is now [refcode]
Try changing refcode= in the link and reload this page. Let me know if you have any further ideas for expanding this plugin.
You can download the latest copy here.
If you want to be able to build plugins like this yourself, click here and more.
- Grandpa’s Handyman Secrets by Dr Miles Bader – Lowest Price
- Lockheed Martin RQ-170 Sentinel – Beast of Kandahar
69 thoughts on “Cookie Monster – WordPress URL Parameter Utility”
- ← Older Comments
I used to be able to pass the cookie value into a form field by placing this inside the field value:
But now I can’t get that to work. Any ideas?
actually, I just figured out a new way:
Replace ref with whatever your cookie parameter is.
It is truly a nice and helpful piece of info. I am glad that you simply shared this helpful information with us. Please stay us up to date like this. Thank you for sharing.
Is there any reason why wpautop is added to this plugin?
Not sure if this comment string is still active… but I have a question about passing MULTIPLE variables and how the href html should be coded.
Example: I set up 2 variables to pass…
1) id -> affiliate id
2) c -> campaign id
I embed those variables into the href code (to create a live link) and separate the 2 variables with & as follows…..
Here is the how the html href is coded:
It works great IF there ‘are’ 2 variables… say id=123 and c=facebook
…then it pulls up live link like this:
http://www.example.com/link.php?id=123&c=facebook -> perfect!
BUT… if there is ‘only ONE’ variable say id=123 and c is NOT identified at all in the original URL …then the href link pulls up this site:
The ‘&’ sign sticks on the end…
Is there a better/correct way to do this so that the href html does not pull up the & sign when there is NO 2nd (or 3rd, 4th…multiple) variables?
It seems as though on most computers the cookie does not set anymore … the cookie works on the original page … but when you surf to other pages it goes back to the default ?? Any suggestions
what if the referral id is in front of the domain
I get a PHP Notice in logs:
PHP Notice: Undefined index: from in /var/www/ecofit.ru/wp-content/plugins/cookiemonster/Cookie.php on line 19
In line 19 of the file I have:
$g_refcode = $_COOKIE[$cookie];
Can you please help to fix this ?
This plugin doesn’t seem to work well with optimizepress. It interrupts the video on the page. any ideas on why this happens or how to get around it?
Can this plugin be used with Optimize Press 2?
What about adding the ability to pass the variable to a custom field in an autoresponder…Say aweber…So that when I mail leads I can actual mail the referers id
Works great except that it creates a and in gravity forms for some reason. Can you fix this? I am willing to pay you for your time as otherwise it does what I need. Cheers
why wpautop is added to this plugin?
all design are break bcoz of auto added p and br tag, i’m using themify theme & using themify builder.
Thanks Vish, this has been resolved. The new version 1.51 should work, give it a try.
I’m using version 1.51 on my site within the Instabuilder plugin. My URL Parameter is id – When I add [id] to the end of a URL – It works fine for all affiliates BUT if I go back into that page to edit something – the [id] automatically changes to the default? I then have to go into each area where the link is – change it back to [id] save and quickly get out! As long as I don’t go back in to do any work on the page it works fine.
I use CM on another site without Instabuilder and I don’t have this problem …. Is this a conflict with the Instabuilder plugin pages??
I’ve just recently started using CM, and it seems to work as expected. But, subsequent page loads don’t see the cookie name in $_COOKIE, even though it’s clearly in the cookie cache of Chrome, and seems to be sent in the Cookie header. A couple array variables are set, but not the CM ones. This is across many page loads, not just the first rendered page. Thoughts?
I’m experiencing issues with the Cookie Monster plugin when a url parameter contains an underscore.
Some of our advertising platforms use underscores in the parameters like “utm_adgroup” and things similar to this to identify what ad an user comes from.
When a parameter is just one word, it sets a cookie perfectly. When a parameter contains an underscore it doesn’t set a cookie. It looks like the underscore breaks the plugin.
Can you offer any assistance?
Why is the Cookie Monster only working correctly on my computer? When others use the coded link it is not working correctly?