Find Answers and Get Support › Forums › Gwangi – PRO Multi-Purpose Membership, Social Network & BuddyPress Community Theme › Theme Customizer › Pages › Redirect page for unregistered users
- This topic has 5 replies, 2 voices, and was last updated 6 years, 5 months ago by
Themosaurus.
-
AuthorPosts
-
alexParticipant@abourne
- 81 Topics
- 259 Posts
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
November 3, 2018 at 17:23 #3249@themosaurus- 1 Topics
- 1675 Posts
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:
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,
November 5, 2018 at 17:52 #3318alexParticipant@abourne- 81 Topics
- 259 Posts
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?
November 15, 2018 at 12:33 #3515@themosaurus- 1 Topics
- 1675 Posts
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.
November 17, 2018 at 17:25 #3615@themosaurus- 1 Topics
- 1675 Posts
You’re welcome. ?
Best regards,
November 20, 2018 at 17:27 #3676 -
AuthorPosts
The topic ‘Redirect page for unregistered users’ is closed to new replies.