Entrepreneur, WordPress Enthusiast & Digital Marketing Strategist

Use HTTP GET Variable's in your WordPress Posts & Pages

So in a recent project I needed to push some non-sensitive client submitted data to a WordPress page and found quickly that there was no easy way to pull in a GET variable into my post/page content. I quickly realised I could solve this problem with a quick shortcode added to my theme functions.php (you could also embed this in your custom plugin):

Just to quickly run through this, to use the shortcode you simply call the shortcode and set the variable name you want to pull the GET variable for.

So if your URL is: /my-awesome-page?foo=1234

You would use the shortcode [get_get_var varname=”foo”] which would return “1234”.

In my scenario this allowed me to generate a list of custom posts based on the user selected time range by embedding this shortcode within a calendar plugin shortcode for selecting dates. This looks something like:

[calendarplugin startdate=”[get_get_var varname=’foo’]” enddate=”[get_get_var varname=’bar’]” ]


Hopefully this makes sense and you guys can find some use for this snippet. Feel free to leave a comment with your thoughts.

Categories: Wordpress


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