-
Notifications
You must be signed in to change notification settings - Fork 34
Frequently Asked Questions
- How can I specify a redirect URL on login?
- How can I add exceptions for certain pages or posts?
- How do I hide the "← Back to {sitename}" link on the login screen?
By default, the plugin sends visitors back to the URL they tried to access. However, you can redirect users to a specific URL by adding the built-in WordPress filter login_redirect to your functions.php file.
You can bypass Force Login based on any condition or specify an array of URLs to allow by adding the following filter to your functions.php file.
You may use the WordPress Conditional Tags in your code.
/**
* Bypass Force Login to allow for exceptions.
*
* @param bool $bypass Whether to disable Force Login. Default false.
* @param string $visited_url The visited URL.
* @return bool
*/
function my_forcelogin_bypass( $bypass, $visited_url ) {
// Example 1: Allow these pages
if ( is_page( array( 'my-page', 'Another Page', 1234 ) ) ) {
$bypass = true;
}
// Example 2: Allow these absolute URLs
$allowed = array(
home_url( '/my-page/' ),
home_url( '/2015/03/post-title/' ),
);
if ( ! $bypass ) {
$bypass = in_array( $visited_url, $allowed );
}
return $bypass;
}
add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );Check out the Bypass Dynamic URLs page for additional examples for allowing dynamic URLs.
The WordPress login screen includes a "← Back to {sitename}" link below the login form; which may not actually take you back to the site while Force Login is activated. You can hide this link by adding the following action to your functions.php file.
Requires: WordPress 2.5 or higher
// Hide the 'Back to {sitename}' link on the login screen.
function my_forcelogin_hide_backtoblog() {
echo '<style type="text/css">#backtoblog{display:none;}</style>';
}
add_action('login_enqueue_scripts', 'my_forcelogin_hide_backtoblog');