Redirecting users to a specific page tailored to their needs or interests immediately after they log in can create a smooth and efficient transition, saving them time and effort. For website owners, it’s a wonderful way to effortlessly guide users toward key areas or promotions.
With Divi, creating a customized login page for your website is a breeze using the Divi Login module. This module provides a login form for your registered users and includes a convenient redirect option that can be activated with a simple toggle in the settings, although the default redirect option is limited to the current page only.
In this guide, we’ll show you how to modify Divi’s login module redirect to a custom URL of your choice without the need for installing extra plugins.
Setting Custom Redirect URL for Divi Blog Module
Step 1: Adding the Custom URL
First, copy the URL of the page where you want users to land and add this URL to the following code snippet as the value for the $redirect_to
variable.
add_filter('et_pb_login_shortcode_output', 'wpp_login_redirect'); function wpp_login_redirect($output) { if (is_user_logged_in()) { return $output; } //Add your custom URL below $redirect_to = 'https://yourcustomurl.com/'; $output = preg_replace('/<input type="hidden" name="redirect_to"[^>]*>/s', '', $output); $output = str_replace('</form>', '<input type="hidden" name="redirect_to" value="'.esc_attr($redirect_to).'"/></form>', $output); return $output; }
The above code will replace the hidden redirect URL of the module, which is the current page, with your custom URL.
Step 2: Integrate the Custom Code
Once the code is ready, it’s time to integrate it into your website. We suggest a safer approach for integrating custom code by using a child theme or creating a custom plugin, rather than directly adding it to the main functions.php file of the Divi theme.
If you opt to use a child theme, you can easily locate the functions.php file from the Appearance → Theme File Editor menu on your admin dashboard and add the code to the bottom of the file editor.
Click the Update File button to save your changes and apply the new login module redirect URL.
Now, every user who logs in using the Divi login module will be redirected to the custom URL of your choice.
The Bottom Line
By implementing a custom redirect URL after login, you can significantly enhance the user experience on your website, making navigation more intuitive and personalized.
Follow our guide to modify the login module redirect, and enjoy the benefits of a smoother, more engaging user journey.