Skip to content

Instantly share code, notes, and snippets.

Last active Mar 21, 2022
What would you like to do?
If elseif else shortcode example
// See this comment:
* Add this code into your theme's functions.php file (or custom plugin).
add_filter( 'query_vars', function( $vars ) {
// Add any other $_GET params you want to use.
$vars[] = 'paramName';
return $vars;
function param_is( $param_name, $val ) {
return $val === get_query_var( $param_name );
add_filter( 'if_elseif_else_shortcode_allowed_callables', function( $whitelist ) {
$whitelist[] = 'param_is';
return $whitelist;
/* Shortcodes to use:
[if param_is paramName value1]
text option #1
[elseif param_is paramName value2]
text option #2
text option #3
Copy link

devidw commented Mar 21, 2022

When you don't want to whitelist every GET parameter:

function param_is( $param_name, $val ) {
	return isset($_GET[$param_name]) && $_GET[$param_name] === $val;

Copy link

n8kowald commented Mar 21, 2022

There should be a tailing ; after the last add_filter() call, when we are not using a closing ?> tag:

Thanks David. I've updated the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment