Accessing URL Query String (Get Variables) inside WordPress through PHP

Adding this to your template file or functions.php in some cases will allow your PHP scripts to access variables passed in the URL query strings.  You know, that ugly text after the Question mark in the website address:  “http://tools.belchamber.us?variable=value&variable2=value”.  Most of you probably already figured out just looking at these type of URLs that some values are being passed from one page to another.  The variables extracted this way are called “Get variables” and aren’t very secure.

Remember to avoid passing any sensitive or personal data inside a URL — anyone can view it on the address bar, or worse yet – in your browser history!


function add_query_vars_filter( $vars ){

$vars= array("var1","var2","var3");

return $vars;

}

add_filter( 'query_vars', 'add_query_vars_filter' );

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

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