Simple redirect unauthenticaed WordPress users

Put this at the top of your template you want to restrict:

<?php
/**
 * If user's not logged in, send to login page.
 */
if (!current_user_can('read')) {
    header('Location: ' . wp_login_url(get_permalink()));
    exit;
}

Leave a comment

Your email address will not be published.