Redirect After completing registration form

Hi,

I want to publish a custom snippet that redirect the user (to the homepage) after he completes the registration.

Here’s the code:

function custom_hivepress_redirect_script() {
    if (is_page('**registra**')) {
        ?>
        <script type="text/javascript">
            document.addEventListener('DOMContentLoaded', function () {
                var observer = new MutationObserver(function (mutations) {
                    mutations.forEach(function (mutation) {
                        if (mutation.addedNodes.length) {
                            mutation.addedNodes.forEach(function (node) {
                                if (node.nodeType === 1 && node.innerText.includes('**Controlla la tua email per attivare il tuo account.**')) {
                                    window.location.href = '<?php echo home_url(); ?>';
                                }
                            });
                        }
                    });
                });

                var config = { childList: true, subtree: true };
                observer.observe(document.body, config);
            });
        </script>
        <?php
    }
}
add_action('wp_footer', 'custom_hivepress_redirect_script');

This code works based on the notification that comes after registration. Also, I’m using a custom page for registration.

Remember to replace the bold text with yours. It’s in Italian in my case!

Thanks!

1 Like

Hi,

Thank you for your solution, it will be useful for our community.