Passing url parameters to a WordPress page

Do you need to pass URL parameters between pages in your WordPress site? Here's a solution to do it with a little plugin code and a small template file change.
20 May, 2010

Have you ever tried to tweak your wordpress website in a way that requires you to pass parameters to a page? Perhaps you have tried to embed a piece of 3rd-party code into your page and found that it doesn’t work because the code requires a url parameter to have been passed to it – and the parameter seems to have vanished as the page loads?

The reason for this is that WordPress automatically strips out parameters it doesn’t recognise before it builds your pages. The solution is to trick WordPress into accepting your parameters as though they were integral to the framework. I couldn’t find an ‘official’ wordpress plugin to allow me to do this, but came across this solution (credits below)….

You will need to edit the template file which loads the page you want to receive the parameter, and you will need to upload some code as a plugin to name the variable(s) that you want to use, but it seems to work well.

Here is the plugin code, which needs to get uploaded to your plugins folder and activated….

/* Plugin Name: Parameter
Plugin URI:
Description: A plugin to allow parameters to be passed in the URL and recognized by WordPress
Author: Adam Boyse
Version: 1.0
Author URI:
add_filter('query_vars', 'parameter_queryvars' );
function parameter_queryvars( $qvars )
$qvars[] = 'yourvarname';
return $qvars;

…and here is an example of how to use it in your template page….

global $wp_query;
if (isset($wp_query->query_vars['yourvarname']))
print $wp_query->query_vars['yourvarname'];

You need to change yourvarname to the name of the variable your page expects to receive.


Thanks to for pointing us at the solution to this problem.

If this was useful to you, please leave us a comment or like / share with your social media networks. This encourages us to post more useful code snippets and website fixes.

We do a lot of work on WordPress sites, and so if you have a tricky problem you’re trying to resolve please get in touch and we’ll help out if we can.


  1. Jon Davies


    Thanks for this idea. It’s a neat way of passing arguments in wordpress. I used it for a training website I was working on ( to customise the contact us form depending on which page it was clicked from. It works a treat.

  2. Daniel

    You said in the article I need to change ” yourvarname to the name of the variable your page expects to receive” — where do I find this?

    • Martin Jarvis

      Hi Daniel.
      Your variable name should be apparent to you from the parameter string that you’re trying to read in your WordPress page. For example, if your parameter was something like ‘’ then the variable name would be ‘searchparam’.

      • didier

        Hi, what is I have more than 1 var I want to pass, like name and idm can I just add them in the php and template?


        • Martin Jarvis

          Hi Didier.
          It’s quite a while since I wrote this post, so I’m not 100% sure but I think you would just repeat the code for each parameter, something like this…

          add_filter(‘query_vars’, ‘parameter_queryvars’ );
          add_filter(‘query_vars’, ‘parameter_queryvars1’ );
          function parameter_queryvars( $qvars )
          $qvars[] = ‘myparam1’;
          return $qvars;
          function parameter_queryvars1( $qvars )
          $qvars[] = ‘myparam2’;
          return $qvars;

          • Paul

            I had the same issue and I found that this proposed fix didn’t work. I eventually succeeded by editing the plugin code thus:

            PHP Code to pass parameters to WordPress pages

            where param1 and param2 are the two variable names to be passed.

          • Dave

            Great solution for passing one parameter. Thanks. But I am trying to get it to work with multiple parameters. “Paul” seems to have made it work for him but unfortunately Paul you didn’t provide how to process it on the target page and I am having difficulty figuring it out. Can anyone help please, and thanks.

  3. jack

    I’m not sure I understand, how and where exactly would I add the second bit of code – …and here is an example of how to use it in your template page….

    Would I add that code in the full-width.php page template, if that is the template I chose for my pages? Where exactly would I add it? Would that bit of code get wrapped in php tags?

    Thanks in advance –

    • Martin Jarvis

      Hi Jack.
      You would add that code to your template file (full-width.php in your case) or alternatively in your theme functions.php file. I guess it doesn’t really matter where you put the code, as long as it is before the point where you need to reference the passed parameters.

      The code needs to be wrapped in tags, yes.

  4. Jack

    So I could put both sets of code in the functions.php file, the first set of code as well as the second set? I will try that and see, thank you.

  5. Fritz Salzmann

    Wonderful! This is working very well.

  6. Graham

    Thanks for posting this! There is now a plugin that offers this functionality, called URL Params. Cheers, Graham

  7. Martin Jarvis

    That’s a good shout Graham, thanks for letting us know. I wrote this post some years ago at a time when I don’t think this plugin was around. For other readers of this thread, I think the plugin in question is this one.

  8. trey

    How would I rewrite the URL in wordpress to append the new variable to every page in the permalink style.
    would actualy resolve to:


Submit a Comment

Your email address will not be published.

You may also like…

Why is my website traffic falling in Google Analytics?

Why is my website traffic falling in Google Analytics?

Have you noticed your website traffic falling over the past few years? If you use Google Analytics, you may be seeing a decline in traffic. This might not be a genuine decline. We explore the reasons for this in our article.

Why choose WordPress – what’s the fuss?

Why choose WordPress – what’s the fuss?

We decided to become WordPress experts because we believe it to be a great, cost-effective platform for small- and medium-sized businesses. It’s packed full of functionality and a great content management system – in fact, WordPress started out as a blogging platform, but developed into much more.

Share This