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: http://webopius.com/
Description: A plugin to allow parameters to be passed in the URL and recognized by WordPress
Author: Adam Boyse
Author URI: http://www.webopius.com/
add_filter('query_vars', 'parameter_queryvars' );
function parameter_queryvars( $qvars )
$qvars = 'yourvarname';
…and here is an example of how to use it on your template page…
You need to change yourvarname to the name of the variable your page expects to receive.
Thanks to webopius.com for pointing us to the solution to this problem.
If this was useful to you, please leave us a comment or like/share it 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, so if you have a tricky problem you’re trying to resolve please get in touch and we’ll help out if we can.