URL Params

The URL Params WordPress Plugin allows you to access URL parameters in the Query String of the URL.

The plugin even allows you to specify a default value in the shortcode if the parameter isn’t set, so if you want to say “Hello, FirstName” and FirstName isn’t set, it could say something like “Hello, Friend!”

To specify a backup url paramater, enter multiple paramaters seperated by commas. The plugin will check for each paramter, in order, until a matching one is found and return that. Failing finding any of the paramaters you listed, the default will be returned. For example, you can specify [urlparam param="FirstName, First, name" default="Friend" /] to check for FirstName, and if not found, then First, if not found, then name, and if not, then just return “Friend”.

This is great if you have personalized links, like from Infusionsoft, as it lets you personalize a landing page with a persons name.

You can also use this to pre-fill out form fields for folks based on the querystring. For example, if their first name is passed in the URL, your landing page can greet the viewer by name and pre-fill their name on a form.

Installation:

To install the plugin, download the zip file and upload via the plugin interface of your WordPress site.

Usage:

Use the shortcode urlparam with the optional parameter of “default”. For example or [urlparam param="FirstName" default="Friend"/].

Updates:

  • 0.3: Released 6/25/2011. Added support for alternative paramters, i.e. param=”FirstName, First, name”

I’m always open to suggestions and ideas on how to improve this plugin. Please make suggestions by commenting below.

25 thoughts on “URL Params”

  1. Hi Jeremy,
    I’m trying to pass parameters via URL for the purpose of showing a different tracking phone number depending on the URL parameter passed, and in my efforts I found your plugin. The problem is that once the user clicks to a different page, the parameter is no longer there. The solution I think is to use some global variable or session data, but my PHP skills aren’t that great so I’m just trying to hack it all together. Is there a way to store a url parameter to a session variable and the call that data later after the user has clicked to a different page?

    Not to dilute from your plugin, obviously if there is way to do this with it that would be great, but my approach prior to finding your plugin was to use this code:
    (wordpress will probably filter some of this syntax)

    $val = $_GET[‘trackingphonenumber’];
    if(empty($val)) echo “Call us at 555-1212”;
    else
    echo “Call us at $val”;

    But I’m not storing that data to a session or calling it back.
    Any suggestions as to how I can mod your Plugin or my own code to make this work between pages?

    1. Great question! For starters, to do what your code does, you’d just use this:

      Call us at [urlparam param="trackingphonenumber" default="555-1212" /](

      To keep it between sessions and not get too complicated with plugins or PHP, just use Javascript. Have the JS check for the paramater. If it’s there, set a cookie. On subsequent page loads, have it check, if the cookie is set, have it modify the spot for the phone number on the page.

      Are you looking to embed this phone number in your site’s theme, i.e. on all pages? In that case, you can just hard code it with PHP in your child theme using PHP Sessions. (more info at http://www.php.net/manual/en/book.session.php )

  2. GoToWebinar Registration

    Thank you for creating this. I’m not sure how else to contact you, but is it possible to get more information about how to implement the plugin?

    Thanks
    Fred

  3. Dear Jeremy!
    I have some problems using your plugin tag within another tags.
    I.e. standalone [urlparam param="email" /] is working but if I’m including [urlparam param="email" /] into Shortcode Exec PHP tags like [subscribe][urlparam param="email" /][/subscribe] – the page generated contains a tag but not its value. So the “subscribe” script will receive [urlparam param="email" /] but not its value 🙁

    1. In order for a shortcode to be inside of another shortcode, the outside shortcode needs to run do_shortcode() on the return value. Most shortcodes don’t do this so that won’t work. If you want, go edit the code for your subscribe tag and set it up to return do_shortcode() on the return value. 🙂

    1. Sounds like there might be an issue with another plugin you have installed. Try disabling other plugins until you find the culprit! 🙂

  4. Hi Jeremy, I love what this plugin does.

    Question: how specifically do I set this up to have it work with a form.
    I use infusionsoft. I already setup the link to pass the customer information.

    On your examples above it specifies how to set it up as a “hello “john”” for example, but I am not sure how to set it up as to when the client arrives in the site, the form is pre-filled.

    Thanks in advance for your response.

    Jim.

  5. Jeremy, i’m using your great plugin on a few sites. I tried recently to deploy to a multisite installation and there seems to be some incompatibility with the Domain Mapping plugin. Are you aware of any other users communicating any difficulties when using URL Params with Multisite?

    1. There shouldn’t be any conflict with Multisite, Joe. It’s most likely another plugin botching up the reading of the params. 🙂

  6. Hello Jeremy

    I’m trying to use urlparam to take the query string coming in a post and pass it to a link in that same post but I can’t quite figure out how to build the href attribute of the tag… the value needs to be the page
    – user goes to
    https://mysite/blog/2015/06/03/test-a/?country=CA&zip=N1T
    in this post I need to build the href to send user to another post passing the same query string Test b

    I can get the values for the query string fine, but can’t figure out how to build the href…

  7. Is there an all-in-one solution for reading a parameter, then setting that parameter as a cookie? Or if I use your plugin, do I need to write my own Javascript for the cookie values?
    My ultimate goal is to be able to pass that same parameter/cookie value in a link to another site.
    Thank you.
    -Mark

    1. Great question, Mark! URLParams also checks cookie values (technically, we’re checking $_REQUEST which checks GET, POST, and COOKIEs) so we’ll be able to process cookies sent to your server. That being said, we don’t SET any cookies for you. You’d need to use javascript (or some other backend plugin) to do that.

  8. Hi Jeremy,

    I love this WordPress plugin!

    I have a question. When I upload a page to my wordpress site through my external page builder (Leadpages is the one I use) the plugin doesn’t work. How can I solve it? Is there a code I can place in the page in Leadpages?

    Thanks

    1. Thanks, Lucas, and that’s a great question! I believe that when Leadpages publishes to your WordPress site, it’s publishing a wholly packaged self-contained page that doesn’t run through WordPress’ standard parser which processes shortcodes hence shortcodes not working on a Leadpage page even if it’s published to your WordPress site. Check with Leadpages support, though, and let me know what you hear back about how you can use WordPress shortcodes on a Leadpage published page…

  9. Hi Jeremy,
    I’m trying to get the parameter from the current URL in WordPress.
    Just looking at your plugin and noticed it hasn’t been updated for a couple of years.
    Just wondering if it’s still going to work for WP 5.7.2 or isn’t is being developed anymore?

    With Thanks,
    Chris

Leave a Reply

Your email address will not be published. Required fields are marked *