• Resolved webalot

    (@webalot)


    Hi,

    Originally the site was not multilingual.
    I made a code snippet so only logged in users could see the store page (https://www.treeclix.com/store), otherwise they would be redirected to the account page to login.
    This is the still working code snippet:

    add_action( 'template_redirect', 'redirect_to_specific_page' );
    
    function redirect_to_specific_page() {
    
    if ( is_page('store') && ! is_user_logged_in() ) {
    
    wp_redirect( 'https://www.treeclix.com/my-account/', 301 ); 
      exit;
        }
    }

    I installed WPML and cloned the snippet.
    I first changed the check for store to ‘winkel’ and also to the ID 715, but this snippet is not working:

    add_action( 'template_redirect_nl', 'redirect_to_specific_page_nl' );
    
    function redirect_to_specific_page_nl() {
    
    if ( is_page( 715 ) && ! is_user_logged_in() ) {
    
    wp_redirect( 'https://www.treeclix.com/nl/mijn-account/', 301 ); 
      exit;
        }
    }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter webalot

    (@webalot)

    Changed the first code snippet to:

    add_action( 'template_redirect', 'redirect_to_specific_page' );
    
    function redirect_to_specific_page() {
    
    if ( is_page( array( 'store', 'winkel' ) ) && ! is_user_logged_in() ) {
    
    wp_redirect( 'https://www.treeclix.com/my-account/', 301 ); 
      exit;
        }
    }

    This worked, although it will not be redirected to the translated my account page, but that is not much of a problem.

    Plugin Contributor Verdi Heinz

    (@ver3)

    Hi @webalot do you still need help? We love helping in any way possible although the focus is on the plugin and our own code. For content we started this community, chances are there are more WPML users there.

    Code Snippets Community on Facebook:
    https://www.facebook.com/groups/codesnippetsplugin

    Ps. if you’re happy with Code Snippets please leave a brutally honest review for us right here in the WP Repo. It really means a lot to us:
    https://ww.wp.xz.cn/support/plugin/code-snippets/reviews/

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘redirection not working with wpml’ is closed to new replies.