This function can be used in multiple different ways to set conditional content based on specific URL query strings. It should be placed in your theme’s functions.php file or into a new plugin.

This function is fairly simple to understand a break down to use any way you need.

The function itself requires two parameters. The first $para is looking for the URL parameter, and the second, $string, is looking for the query string.

Calling the function will take a look at the current URL, and return true or false passed on your argument.

For example, if my URL were…

http://mysite.com/?foo=bar

I could test for this in a page template like so…

test_url_para(foo, bar);

This would return a true result.

Obviously, the parameter I’m looking for in this example is “foo” and the string I’m looking for is “bar” but that can adjusted and/or added to anything you want.

Here’s an example:

http://mysite.com/?foo=bar
test_url_para(foo, bar); // RETURNS TRUE
test_url_para(foo, choo); // RETURNS FALSE
test_url_para(noo, bar); // RETURNS FALSE

Using this URL query test to display conditional content in your template is super easy!

Start talking about it!