I am using this plugin -

Hey guys,

I am using this plugin - https://wordpress.org/plugins/css-javascript-toolbox/ - in attempts to redirect mobile users to a specific page vs the standard video home page that desktop users are taken to.

Clearly I am doing something wrong. My end goal is to have all mobile users be taken to this page - http://yikes.co/what-is-it - while desktop users will be taken to the yikes.co with the video and three buttons etc.

I have enabled the support via the WPMU dashboard utility. You will see the code I currently have used once looking at the plugin but here it is anyways

<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
   location.replace("http://yikes.co/what-is-it/iphone.html");
}
-->
</script>

I know its not your plugin but I was hoping you might be able to offer some insight on what to do.

Thanks for the support!

p.s. the CSS & Javascript Toolbox plugin is located towards the very bottom of the menu on the left hand side.

  • Ash

    Hello @Ryan

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    Would you please try this instead?

    <script language=javascript>
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
       location.replace("http://yikes.co/what-is-it/iphone.html");
    }
    </script>

    Let us know if that works.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • Michael Bissett

    Hey @Ryan, thanks for your patience here! :slight_smile:

    I just tried entering this:

    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
       location.replace("http://yikes.co/what-is-it/iphone.html");
    }

    Into Appearance -> Custom Javascript, and I was able to get it working... somewhat.

    The problem we have at present is, the code introduces a redirect loop for iPhones and iPods viewing the site.

    I've called in our more code savvy fellows in SLS for this, as they'd be more experienced in cooking up a fix for this.

    Hope you're doing well today! :slight_smile:

    Regards,
    Michael

  • Hoang Ngo

    Hi @Ryan,

    I hope you are well today and I'm sorry about the issue.

    That code should be

    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
       location.href = "http://yikes.co/what-is-it/iphone.html";
    }

    Just for clarify, do we need to stick with javascript ?, as when the page render, after a while it will meet the script, and now it will do the redirect, that will make the page look refresh twice before client can check the iphone page.

    If possible, I suggest a solution with php, something like this

    add_action( 'init', 'detect_iphone_redirection' );
    function detect_iphone_redirection() {
    	$user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
    	if ( ( strpos( $user_agent, 'iPhone' ) !== FALSE ) ) {
    		wp_redirect( 'http://yikes.co/what-is-it/iphone.html' );
    		exit;
    	}
    }

    Please add this code to your theme functions.php or use mu-plugins

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.