Cookie Monster – WordPress URL Parameter Utility

cookie monster girl

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.

If you want to be able to build plugins like this yourself, click here and more).


62 thoughts on “Cookie Monster – WordPress URL Parameter Utility

  1. Brian M

    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?

  2. Brian M

    actually, I just figured out a new way:



    Replace ref with whatever your cookie parameter is.

  3. blog network

    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.

  4. Frank

    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?

    Thank you!

  5. Cynthia

    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

  6. Roman

    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 ?

    Thank you,

  7. Shayn

    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?


  8. JOhn

    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

Leave a Reply and Let me know what you think...