I am a novice with php, so I need help with this one. Please bear with me.
I want to include an error message on the wp_login.php page when visitors are redirected from a "user only/logged in" page. Below is the code I have for the page template which I use for "users only." It checks if the user is logged in or not. if he is not, he is redirected to the login page. This is where I get stuck. I tried to but together some code I found on google but no luck. Is there a way to pass an error message from here to the login page?
if (!is_user_logged_in()) { auth_redirect(); }
add_action('login_head','ref_access');
function ref_access() {
global $error;
if( !empty($_GET['ref']) && 'access' == $_GET['ref'] )
$error = 'Restricted area, please login to continue.';}
Any code suggestions would be appreciated.