Aleš Sýkora wrote

Redirect non logged users to login page

Situation: Website with pages restricted only to logged in users and we do not use toolset content templates but Oxygen Builder. We are hiding the content to the non-logged in users with Oxygen conditionals but we would like to redirect user to the login page instead of displaying login form on every restricted page.

Code snippet for redirection to custom login page:

add_action( 'template_redirect', 'redirect_visitors_to_login' );
function redirect_visitors_to_login( $template ) {
    // if current visitor is not logged-in
    if ( !is_user_logged_in() ) {
        // list of pages to exclude from the redirect
        $excluded_page_ids = array(12, 14, 16, 18);
        // ID of the login page where visitors should be redirected to
        $login_page_id  = 12;
        // if the current page is not among the excluded pages
        if ( !is_page( $excluded_page_ids) ) {
            // redirect to the login page
            wp_redirect( get_permalink($login_page_id) );
    return $template;

Please replace 12, 14, 16, & 18 with the actual page IDs of the excluded pages on your website.

Other way – when you are using Toolset Access and Toolset Content templates, is creation of custom content template for the Access Group and use meta redirection in it.

<meta http-equiv="refresh" content="0; url=" />

Change the URL to your login page.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Tracking Toolset Forms in Google Analytics with Google Tag Manager
7. 8. 2018 in
What if you want to track your Toolset Forms submissions with Google Analytics Events? See how to do this with Google Tag Manager quickly.
Read More
Aleš Sýkora wrote
Fluent Forms activation – You do not have sufficient permissions to access this page.
25. 3. 2021 in
If you got “You do not have sufficient permissions to access this page.” error when you click on activation of Fluent Forms Pro licence, you need to go to the integration modules settings of Fluent Forms plugin and activate the plugin from there.
Read More
Aleš Sýkora wrote
Shortcode to display word count or reading time
1. 7. 2019 in
This shortcode "word-count" will display a count of words for whatever content is passed, and can optionally display an estimated reading time.
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram