I am trying to get a custom URL parameter from a URL in WordPress.
I add the following code to functions.php:
function add_query_vars_filter( $vars ){
$vars[] = "token";
return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );
Then on the webpage I write:
<?php $token = get_query_var( 'token', $default = ''); ?>
<h1>Currently Browsing token <?php echo (int) $token; ?> On a
static front page</h1>
and go to the webpage http://www.negovista.com/tokensuccess/?token=xxxxxx
However on the page is only printed
'Currently Browsing token On a static front page' without the xxxxxx
Anyone knows if there is an error in the code?
$token
var?<?php $token = get_query_var( 'token', $default = ''); ?>
and<?php echo (int) $token; ?>
statements are printed as HTML comments (<!--?php $token = get_query_var( 'token', $default = ''); ?-->
and<!--?php echo (int) $token; ?-->
). It seems some error in the syntax wihtin your php template file.function rj_add_query_vars_filter( $vars ){ $vars[] = "adminoption"; return $vars; } add_filter( 'query_vars', 'rj_add_query_vars_filter' ); echo get_query_var('adminoption', "<h1>NOT SET</h1>");
. My code always returns "NOT SET" my url query is "sometitle/?adminoption=TEST"echo $_GET["adminoption"];
works fine. I can get that to print out whatever I want. This is in my functions.php file