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”
- Newer Comments →
Thanks for sharing, very useful! You just saved me one or two hours of coding 🙂
Is there any way to use this in themes?
I think I may have answered this myself.
[code]
<?php
echo $_COOKIE[get_option('cookie_param1')];
?>
[/code]
Yes Casey, that should work Let me know if it did, and send us a link to your site so we can check it out. Thanks!
Over my head, I do try to learn new techy things, but didn’t understand this.
HI,
This is EXACTLY what I was looking for! Thank you so much.
I have an odd error message on my site when I use it though:
Warning: Cannot modify header information - headers already sent by (output started at /home/salesex/public_html/wp-content/themes/Delericon/single.php:7) in /home/salesex/public_html/wp-content/plugins/cookiemonster/Cookie.php on line 17.
Any ideas how I address this?
I have seen that error before. It is usually because your theme is sending output before CookieMonster is called. Look for any spaces before php in single.php. If you still cannot figure it out, let me know and I will send you an email address that you can send your file to me and I will take a look at it.
gsmith – You are exactly on the money. I had gaps in my header file that clearly only were brought to light when I installed CookieMonster.
Thanks for your reply – I really appreciate it!
Al
Very helpful plug-in, Gary. When I pass multiple parameters, the values are stored in the cookie but the page won’t display. It generates a 404 error.
What’s the right way to pass
multiple params?
Chris, I am not sure I follow your issue. When you say multiple parameters, do you mean like,refcode=CookieMonster&refcode2=cookie2. This works fine on this page, where are you getting the 404? Try this and you will see the second parameter value at the bottom of the blog post:
http://www.z-car.com/blog/2009/12/05/cookie-monster-wordpress-url-parameter-utility?refcode=CookieMonster&refcode2=cookie2
There seems to be a built-in limitation with WP processing very long URLs. It fails somewhere when the URL is too long and/or too many parameters are passed. This happens regardless of using the plug-in or not.
Unfortunately, I’m using it with Aweber and the default option to pass params to the thank you page blows past the WP limitation. Then the 404 error appears.
.-= Chris´s last blog ..Headlight signup process =-.
Superb Site – Thanks for the info
This works brilliantly for my outgoing links and passing a hidden variable in a form. Thanks you!
.-= Kathy´s last blog ..Avoiding Soreness when Starting Weight Training for Women =-.
Does it work with seo friendly urls ? like http://www.blogname.com/category/sth/?refcode=sth ?
With normal link in wordpress like
http://www.blogname.com/?p=23&var1=sth&var2=sth2$var3=sth
I can get vars with $_GET[‘var_name’];
but with premalinks (post_id/post-name) it doesn’t work and it shows error 404
Yes Ryan, it works with Permalinks. The example on this post is a permalink. Let me know if you have any problems getting it to work.
Thanks for reply. But I have already used tips from http://youngdutchdesign.com/rewrite-multiple-get-variables-for-wordpress-plugins.
Greetings,
Your plugin looks excellent and very useful. I just installed it on WP 3.0 and get the following error message:
options-general.php?page=CookieMonster, You do not have sufficient permissions to access this page.
Is the plugin compatible with wp 3.0. Is there something I can change in the plugin php file to make this work?
Thanks for your time,
Liam
When I hit attempt to go into cookie monster admin section, it tells me “You do not have sufficient permissions to access this page.” I am the admin with full permission…
Anyone found a way to fix it? Seems like a perfect little app but can’t use it 🙁 WP3 is showing “You do not have sufficient permissions to access this page.” when going to settings “wp-admin/options-general.php?page=CookieMonster”
To fix the error “You do not have sufficient permissions to access this page” change the following line in Cookie.php:
ORIGINAL:
add_options_page(“Cookie Monster Options”, “Cookie Monster”, 1, “Cookie Monster”, “CookieAdmin”);
UPDATED:
add_options_page(“Cookie Monster Options”, “Cookie Monster”, 1, “Cookie-Monster”, “CookieAdmin”);
(the difference is to add a hyphen between Cookie and Monster in the 2nd last parameter)
Maybe it’s just me, but where do I find the shortcodes …?
If I go to the admin page and add new vars, all it says is this:
“URL Parameter 1 : ex: affcode – This cookie now set to ”
Looks like something is missing …?
I can’t get it to work with premalinks as well (post_id/post-name) it doesn’t work and it shows error 404. Need to mofidy .htaccess ? Pls help.
Custom Permalink structure is : /%postname%/%post_id%/?refCode=[refCode]
Although refCode is in browser cookies and works well inside posts (by pasting [refcode]), it doesnt work in permalink
Please clarify
Can Meison or Anantha send me an example link? I cannot seem to duplicate what you are seeing.
Is there a way of clearing the cookies, other than passing blank parameters via the url that is?
I’m a newbie and a bit unclear
I’m getting the same thing as Mikkel here above
Now, When I hit attempt to go into cookie monster admin section, it tells me “You do not have sufficient permissions to access this page.” I am the admin with full permission…
I checked and there’s a hyphen as you suggested previously.
Michah, make sure that you have the most recent version, it should have fixed the permissions issue with WP 3.0.
For you and Mikkel, after you go to the admin page and create a URL parameter, until you set that cookie by placing ?refcode=something on the querystring, that value will be blank. Hope that makes sense. Let us know if you have any further issues.
can someone show me an example for writing a url using this plugin?
I got the plugin installed but I cannot figure out how to get it to write my url.
param1 = a
param2 = v
param3 = i
http://param1.param2.com?tid=param3
@gsmith:
I’m still baffled. On some of my pages, it works, and on others it does not.
Could you explain what you mean when you say I need to “set that cookie by placing ?refcode=something on the querystring”?
Case in point, I have added a variable ‘gallery’ in the Cookie Monster settings, and I have called a page with “?gallery=foobar” appended to the URL – shouldn’t that work …? It doesn’t. I can’t access the ‘foobar’ value on the page, and in the Cookie Monster settings it still just says “URL Parameter 3 : gallery – This cookie now set to”
Do I need to treat the variable in any special way on my page? I use $_GET[‘gallery’] to retrieve the value, but it comes out blank …
Okay – I’m closer to the root of the problem now: It doesn’t work on pages that are password-protected!
If I remove the protection, everything is fine, but I would like to avoid that.
Is this a known bug or limitation?
Pingback: CookieMonster-plus • Mercs LLC
Maybe I am missing something, but when I want to use the refcode to store a variable, and then have that variable (keyword) displayed in a post, what code will I use?
I can’t figure out what exactly to type in the settings parameter input box.
And I don’t know what to write as the shortcode to put in my page. Any chances you could set me on the right track?
This is brilliant. Solved two tricky features my client wanted in one! Thanks and thanks all foor the good support.
I agree with AARON. I can not figure this out. Is there a way someone can do a Video on this real quick to help figure this out.
Thomas/Aaron/AJ, I felt the same way, then I figured it out.
Go into Settings > Cookie Monster, and enter the variable name you with to use. Then in your code, you’d place the shortcode (same name as variable name). Example, if I had a variable called refid, I’d enter it into the Cookie Monster config, then in my code, I’d do the following:
<a href="http://www.mysite.com/index.php?refid=%5Brefid%5D
Hope this helps.
I’m very happy to have found this plug-in, but I too have landed the dreadful 404 error.
I know that the variables were passed and cookie set, because if I return to the admin page it tells me the value of my four variables.
It seems to have the problem if I try to pass more than one variable to through the URL. i.e. ?month=3 is fine, but ?month=3&day=12 throws up 404 error.
I have been looking all over for how to answer this question for a plugin I am building. This seems to do the trick in general, but does not work within the plugin. I have a static page http://dev.flyingdogsbaseball.com/pages/player-info that I would like to display info based on the ID passed in the URL , for example http://dev.flyingdogsbaseball.com/pages/player-info?playerID=139. As you can see in the second link, the playerID is picked up and displayed using the shortcode on the page, but the variable is not available for use in the plugin. I am using the following in my code as was mentioned in an earlier comment:
$player_id = $_COOKIE[get_option(‘playerID’)];
$player_id is later used in an SQL query to return the information related to the player. any advice is much appreciated.
I am having a similar issue like Jason.
The plugin reads the first refcode just fine but any subsequent variable is not picked up.
I DO NOT get a 404 page when I use multiple refcodes. The only current issue is that only the first refcode is stored as a cookie.
Any help would be appreciated.
This is a fantastic plugin that I have been looking for a while. Hopefully you will continue to support and make it better.
Pingback: Worpress Plugin Modification
Any chances i can inplment it on my none WP website?
The parameter is not adding on every link on a page, specially on wp_nav_menu.
Can you please give me a hint on how can I fix it?
Hi there
Awesome little plugin, but I have one question. If you use the [shortcode] on a page and a person refers with an ID, then it is great, but what if you want to have a default value in the shortcode in case no referal code is given?
Hi there
Awesome little plugin, but I have one question. If you use the [shortcode] on a page and a person refers with an ID, then it is great, but what if you want to have a default value in the shortcode in case no referal code is given?
Thanks
Martin
also, how can we add more url parameters? right now, I can only add four
Hello Smith,
As the sixth comment, which AL was Monday, March 1, 2010 at 8:32 am
My problem is the same. Using the theme OptimizePress and is giving the error:
“Warning: Cannot modify header information – headers already sent by (output started at /home/suces362/public_html/superoportunidade.net/wp-content/themes/OptimizePress/squeezetemplate_001.php:3) in /home/suces362/public_html/superoportunidade.net/wp-content/plugins/cookiemonster/Cookie.php on line 17”
I’ve tried to follow the step single.php but could not solve the problem, what do I do?
Rafael
Latest version 1.3 allows you to create a default for each parameter. Give it a try and let me know how it works.
I was recommended this website by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my difficulty. You’re amazing! Thanks!
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?