Last active
March 7, 2025 15:06
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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