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 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
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.
20 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…
Joe Hornback´s last blog ..
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)
Post a Comment