Skip to content

Instantly share code, notes, and snippets.

@addisonhall
Last active March 7, 2025 15:06
Show Gist options
  • Save addisonhall/501c76b526a58a6d1e172b0f9c51c93d to your computer and use it in GitHub Desktop.
Save addisonhall/501c76b526a58a6d1e172b0f9c51c93d to your computer and use it in GitHub Desktop.
WordPress shortcode to parse URL query string parameters. Drop into functions.php and add to a custom plugin.
<?php
/**
* Parse query string parameters.
* @example [ahd_parse_query_string param="parameter_name"]
*/
function ahd_parse_query_string_func( $atts ) {
// get shortcode attributes
$atts = shortcode_atts( array(
'param' => '',
), $atts );
$param = $atts[ 'param' ];
if ( isset( $_GET[$param] ) ) {
$value = $_GET[$param];
return htmlspecialchars( $value );
} else {
return;
}
}
add_shortcode( 'ahd_parse_query_string', 'ahd_parse_query_string_func' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment