Wordpress shortcode to show content depending on the value of a URL Paremeter.
Usage examples: [url_parem parem="id" value="1"]Content here[/url_parem] - Will show content if the url paremeter "id" equals "1". [url_parem parem="id" value="1" hide="1"]Content here[/url_parem] - Will hide content if the url paremeter "id" equals "1". [url_parem parem="id" value="1" false="1"]Content here[/url_parem] - Will show content if the url paremeter "id" does NOT equal "1". [url_parem parem="id" value="1" false="1" hide="1"]Content here[/url_parem] - Will hide content if the url paremeter "id" does NOT equal "1".
function url_parem_shortcode($atts, $content = null) {
$a = shortcode_atts(array(
'parem' => '',
'value' => '',
'hide' => 0,
'false' => 0
), $atts);
if (empty($_GET[$a['parem']])) {
$url_parem_value = '';
} else {
$url_parem_value = $_GET[$a['parem']];
}
if ($url_parem_value == $a['value']) {
if ($a['false'] == 0) {
$passed = true;
} else {
$passed = false;
}
} else {
if ($a['false'] == 0) {
$passed = false;
} else {
$passed = true;
}
}
if ($passed == true && $a['hide'] == 0) {
return $content;
}
}
add_shortcode('url_parem', 'url_parem_shortcode');