Support only during business hours : Monday to friday, from 8:30 am – 5:30 pm CEST

Due to the decrease in our staff due to vacations, our response time may be longer.

Be sure we're doing our best to manage your topic as soon as possible.

Redirect page for unregistered users

This topic is resolved
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    How may I customise this snippet to redirect unregistered users to the /register page?

    /**
     * Redirect non logged-in users to registration page if they visit a single post page
     */
    function user_single_page_template_redirect()
    {
    	if( ! is_user_logged_in() && is_singular( 'post' ) ) {
    		wp_redirect( home_url( '/register/' ) );
    		exit();
    	}
    }
    add_action( 'template_redirect', 'user_single_page_template_redirect' );

    The subject page is https://www.gymn.com.au/post/

    Thanks in advanced

    Themosaurus
    Keymaster
    Themosaurus Support
    • 1 Topics
    • 1675 Posts
    @themosaurus

    Hi @abourne,

    To change this, simply add the following code snippet to your website:

    /**
     * Redirect non logged-in users to registration form if they visit any page
     */
    function non_logged_user_template_redirect()
    {
    	if( ! is_user_logged_in() ) {
    		wp_redirect( home_url( '/register/' ) );
    		exit();
    	}
    }
    add_action( 'template_redirect', 'non_logged_user_template_redirect' );

    To add this code snippet to your site, we recommend that you use a the Code Snippets plugin (https://wordpress.org/plugins/code-snippets/). If you have never activated this plugin, please read the following post:

    Adding Custom PHP Without Changing Your Child Theme

    Note that if you use this snippet, all the others pages will no longer be accessible (for example, redirect users to the registration page if they visit a member’s profile). The homepage will no longer be visible either.

    All the best,

    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    Can it be customised to only redirect from the /post page and all associated posts i.e. visiting post page –> clicking on post (all to redirect to registration page).

    Instead of redirecting all pages from the entire website.

    Just as we did for ‘members’ directory and landing on member profiles, can the same be done here?

    Themosaurus
    Keymaster
    Themosaurus Support
    • 1 Topics
    • 1675 Posts
    @themosaurus

    Hi @abourne,

    After making a quick review of your current snippets, it might seems best for you to either deactivate some of them or post all your “redirection” snippets in your next reply so we can merge them into a single one. Otherwise, they might clash with each other as it happened a few days ago with the Location and Location + Gym display.

    What do you think? Ok for you? ?

    Thanks a lot.

    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    Agree. Deactivated most of them.

    A solution for this subject request is no longer needed.

    Thanks.

    Themosaurus
    Keymaster
    Themosaurus Support
    • 1 Topics
    • 1675 Posts
    @themosaurus

    You’re welcome. ?

    Best regards,

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Redirect page for unregistered users’ is closed to new replies.

Troubleshooting Demo Imports

You're trying to setup your theme but you're experiencing errors when importing the demo content? Or you've just followed the setup guide but your website doesn't look exactly like our demo? These are common issues for which you can find easy and quick fixes.

Happy With our Support So Far?

Feel free to review our theme on Themeforest! It helps us making our products more known to new potential customers, which allow us more time to improve the quality and develop new features. #SharingIsCaring ❤️

Discover MatchPress

Skip • Like • Super-Like

Add powerful matching features like Member likes, skips, super likes, conditional private messaging and much more.

Setup Your Cera or Gwangi powered Community Website and Turn it into an iOS and Android App

15% discount for Cera users

To unleash the full power of your Cera or Gwangi theme, we have partnered with the Zipline team. Your community website can now be fully setup and turned into your very own custom app for iOS and Android.

Whether you've newly acquired the theme or already got your site up and running, Zipline got you covered. And we got you an incredible discount.

Holiday, Weather & Festive effects
to pimp your WordPress Site