Skip to content

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 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.

Share and Enjoy:
  • Digg
  • Yahoo! Buzz
  • del.icio.us
  • StumbleUpon
  • Facebook
  • LinkedIn
  • Technorati
  • Mixx
  • Google Bookmarks
  • email
  • Print

20 Comments

  1. Lutz wrote:

    Thanks for sharing, very useful! You just saved me one or two hours of coding :)

    Tuesday, January 19, 2010 at 3:14 pm | Permalink
  2. casey wrote:

    Is there any way to use this in themes?

    Monday, February 1, 2010 at 7:57 am | Permalink
  3. casey wrote:

    I think I may have answered this myself.

    [code]
    <?php
    echo $_COOKIE[get_option('cookie_param1')];
    ?>
    [/code]

    Monday, February 1, 2010 at 8:16 am | Permalink
  4. gsmith wrote:

    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!

    Friday, February 5, 2010 at 12:36 pm | Permalink
  5. sandy wrote:

    Over my head, I do try to learn new techy things, but didn’t understand this.

    Saturday, February 20, 2010 at 11:35 am | Permalink
  6. Al wrote:

    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?

    Monday, March 1, 2010 at 8:32 am | Permalink
  7. gsmith wrote:

    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.

    Tuesday, March 2, 2010 at 12:17 pm | Permalink
  8. Al wrote:

    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

    Tuesday, March 2, 2010 at 1:36 pm | Permalink
  9. Chris wrote:

    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?

    Tuesday, March 23, 2010 at 1:02 am | Permalink
  10. gsmith wrote:

    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

    Friday, March 26, 2010 at 2:06 pm | Permalink
  11. Chris wrote:

    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 My ComLuv Profile

    Friday, March 26, 2010 at 6:08 pm | Permalink
  12. Superb Site – Thanks for the info

    Saturday, April 3, 2010 at 7:30 pm | Permalink
  13. Kathy wrote:

    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 My ComLuv Profile

    Monday, April 19, 2010 at 4:03 pm | Permalink
  14. ryan wrote:

    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

    Thursday, April 22, 2010 at 8:10 am | Permalink
  15. gsmith wrote:

    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.

    Tuesday, April 27, 2010 at 12:03 pm | Permalink
  16. ryan wrote:

    Thanks for reply. But I have already used tips from http://youngdutchdesign.com/rewrite-multiple-get-variables-for-wordpress-plugins.

    Tuesday, April 27, 2010 at 7:24 pm | Permalink
  17. Liam wrote:

    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

    Saturday, June 26, 2010 at 7:06 am | Permalink
  18. Joe Hornback wrote:

    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 ..My ComLuv Profile

    Thursday, July 8, 2010 at 7:29 pm | Permalink
  19. Peter wrote:

    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”

    Monday, July 19, 2010 at 5:24 am | Permalink
  20. bronstar wrote:

    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)

    Sunday, July 25, 2010 at 6:32 am | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*
CommentLuv Enabled