Custom query_var to get URL paramater not working

Question

I have a custom WordPress login and if the user gets to the homepage and is not logged in, they are redirected to the custom login form(I have disabled this for now while I test). What I would like to do is create a URL parameter so that certain users can still get to the homepage without having to log in. From my research it seems like this is possible with a custom query_var. Right now I am just trying to make it work with anything entered into the new query_var and then once I get that working I will make sure it matches a specific value. Here is what I added to my functions.php:

add_action('init','add_var');
function add_var() { 
  global $wp; 
  $wp->add_query_var('auth');
}
if (get_query_var('auth')) {
  echo 'User is visiting from approved URL';
}

I am then adding ?auth=true to the homepage URL, but this does not seem to be working. Nothing is being echoed out. Any ideas?

0
, user13286 4 years 2019-10-24T15:55:29-05:00 0 Answers 58 views 0

Leave an answer

Browse
Browse