• Please I have faced ia problem with wp_redirect function, it is giving redirect loop once called in functions.php and here is the code:
    add_action(‘wp_loaded’, ‘my_icl_set_current_language’);
    function my_icl_set_current_language($lang) {
    global $sitepress;

    wp_redirect( ‘https://www.alwadi-alakhdar.com/?lang=fr’ );exit();
    }

    website url: https://www.alwadi-alakhdar.com

    The website is using WPML plugin, but I have disabled all plugins by renaming the plugin folder and the issue mentioned is still appearing.
    I have tried also to call wp_redirect using “init” filter and even from the header.php , but none of these ways solve the problem.

    So please can you please help me concerning this issue as soon as possible since this is URGENT.

    Thank you in advance,

Viewing 2 replies - 1 through 2 (of 2 total)
  • well, yes, your code is saying:

    1. when WordPress request comes-in
    2. redirect to this url and stop processing this request
    3. browser requests new url
    4. which gets caught by your code for when WordPress request comes-in
    5. repeat ad infinitum

    You need to either not redirect at all, or provide some code which determines whether the redirect is appropriate.

    Thread Starter eastline

    (@eastline)

    I have used also this code: add_action( ‘template_redirect’, ‘my_page_template_redirect’ );
    and this code add_action( ‘init’, ‘my_page_template_redirect’ );

    but both also giving a redirection loop.

    The redirection on our site is mandatory since we have a feature to change language URL based on country IP and this is integrated on the website from scratch bgy identifying the country IP and then change the content and URL langauge to the country IP given or a selected country from a given dropdown.

    I have tried all solutions found on google without finding any success. Please I need your help here, if you can give me the exact way to make a redirection programmatically which avoids a redirection loop.

    I appreciate if you can give me a link to have a live chat with your team, in this case we can have a direct and better communication.

    Thank you,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirection loop once using wp_redirect in functions.php’ is closed to new replies.