• John

    (@johncpatterson)


    Hi all,

    I have been doing a lot of research on how to redirect a single page from my WordPress website to a mobile version (I would like to redirect all mobile users who visit https://lifebyjohn.com/schedule to https://lifebyjohn.com/mobile-schedule, I do not want to redirect all mobile users for all my pages to a different page or theme, only just a single page).

    However, I have yet to find a plugin that can do this. The only one I found that might work is called Equivalent Mobile Redirect, but for some reason that plugin crashed my whole website. I’ve seen a few others that redirect all mobile users for all pages to a different page or theme, but again that’s not what I’m trying to accomplish.

    I’ve also seen a few “scripts” around the internet, most notably https://www.detectmobilebrowsers.com, but most seem incomplete at best, and as a non-website developer I can’t accurately determine which script is best.

    In addition, I have yet to find consensus on “the best” way to detect for mobile devices. Some say to check the “user agent,” others say to check for the height and width of the screen.

    In any event, I’m just looking for an easy way to get a mobile device redirect going for my single page, hopefully through a method that continually “updates” itself so that new mobile phones that come out will get “added” to the list of mobile devices it redirects.

    Any help would be most appreciated!

    – John

Viewing 13 replies - 1 through 13 (of 13 total)
  • Hi John,

    I’m testing WPtouch Mobile Plugin, see plugin description at https://www.ads-software.com/plugins/wptouch/

    Near the bottom of the settings screen, it allows you to determine which WP website pages you want to display in the mobile view, just check the box.

    Hope that helps.

    Equivalent Mobile Redirect does work for me, but it does throw a couple warnings if you have it in debug mode.

    If WPTouch works, I’d definitely go with that.

    As far as User Agent vs screen size, User Agent is the “old” way of doing it. With responsive design, it’s based more on screen size and the actual device doesn’t matter (as much).

    Thread Starter John

    (@johncpatterson)

    @mesquite_murph Thanks for the help. I tried downloading that plugin and I can’t say it’s what I would need, but I appreciate the suggestion.

    @Scriptruner Thanks for the help too. Just even adding the files of Equivalent Mobile Redirect to my website crashes it, so it’s completely out of the question. Thanks also for explaining user agent vs screen size.

    So I must say I’m still looking for a good solution. I am considering using some sort of script that references https://www.detectmobilebrowsers.com or WURFL, but I’m not sure what actual script to type.

    Can anyone else help by chance?

    Thanks!

    One more suggestion for you, try https://www.dudamobile.com

    You can definitely restrict the pages available for mobile viewing. Dudamobile offers a free version which can be synced with your WP website. It also offers a preview of your mobile site before you publish. The formatting options are pretty basic. That might be ok, depends on your page.

    I switched to Dudamobile a couple days ago, and I will keep looking. Let me know if you find something better. Good luck!

    Thread Starter John

    (@johncpatterson)

    Negative on that I’m afraid, I suppose I should have mentioned that I’m looking for a free solution (sorry about that!). I know that there has GOT to be a very simple script out there that I can put in my header to simply route mobile users from one page to another.

    Any other ideas out there by chance? ??

    One possibility would be to use the PHP Browser Detection and put an if statement in your header.php file.

    Check for is_mobile() and the page id you want to redirect on. Shouldn’t be more than a plugin and a simple if/else statement.

    Edit: You may need to put it in page.php. Not sure you can get to page id in header.

    Something like this (but replace your page id with the one you want to redirect on). And this would be with PHP Browser Detection plugin.

    if ( is_mobile() && 2 == get_the_ID() ) {
        // redirect
    }

    This could probably go anywhere after get_header() in page.php.

    Caveat – untested

    Thread Starter John

    (@johncpatterson)

    Hi there,

    I was unsuccessful using the PHP Browser Detection plugin, however I have come across the Shortcode Exec PHP plugin (haven’t used it yet). Having done some research online, I’ve also come across some PHP code that can distinguish between different pages on a WordPress website, such as:

    <?php if (is_page(1111)) {…….}; ?>

    What I’m thinking of doing is putting some kind of mobile redirection script in there, so that I achieve my goal of only needing the mobile redirection to happen for one page on my website.

    However, I have attempted to put the code (both PHP and Javascript) downloaded from https://www.detectmobilebrowsers.com into that PHP code, and have tried putting it in both header.php and page.php to no avail (in fact, it crashes my site in most cases, or just doesn’t work). Am I going about this wrong? Am I using the wrong code? Do I need a plugin to help with that?

    Thanks so much to everyone who can help!

    How did the php browser detection fail? You’ll have to do some kind of user agent detection so I’d go with a plugin if at all possible.

    I do see how it could be handy to have a shortcode, but don’t think I’ve seen a plugin that’ll do that for browser UA detection and redirect.

    Thread Starter John

    (@johncpatterson)

    Well, I’ve tried the following code using the PHP Browser Detection plugin, which didn’t seem to work:

    <?php
    if ( is_mobile() && 2 == get_the_ID(2766) ) {
    wp_redirect(‘https://www.lifebyjohn.com/mobile-schedule&#8217;);
    exit;}
    ?>

    I tried adding the code in header.php, as well as using the Code Snippets plugin so that it would go in functions.php. Did I mess the code up by chance? Or am I putting the code in the wrong place?

    Thanks!

    Hi John

    I got exactly the same question as you, only want to redirect a specific page for mobile users. Allready tried plug ins and different scripts but no luck!

    Any chance you can post the solution you found to your problem?

    I just stumble across this code … Seems interesting, but if i want to apply just to one page of the website, how could i do this?

    if (screen.width < 600 || screen.height < 200) {
        window.location = 'anotherPage.html'
    }

    Thanks in advance!

    Just found an even more interesting solution, you think it could work? Entering this code in functions.php in wordpress and then inserting the shortcode [redirect] inside the page you need, will make the redirect command to mobile devices only work in this page

    //[redirect]
    function myjavascript_func( $atts ){
     return "<script type="text/javascript">
    
    windowWidth = window.innerWidth;
    <!--
    
    if (screen.width <= 767 || windowWidth <= 767) {
        window.location = "https://m.mysite.com";
    }
    //-->
    </script>";
    }
    add_shortcode( 'myjavascript', 'myjavascript_func' );

    In looking around for answer to a similar question, I managed to pull together a solution that’ll probably work for you. In my case I needed to send users on mobile devices to an external URL. That’s easy enough, but the client needed users headed to a different external URL if they were headed to one particular section of the site. First, I use wp_is_mobile to test the browser; if true, then i check the page they’ve requested. If it’s that page or any of that page’s children, they’re redirected to one URL. If it’s mobile but not that page, they’re redirected to a different URL. Works perfectly!

    // add mobile redirecxt
    function xmit_mobile_redirects() {
    	if ( wp_is_mobile()) {
    		if (is_page('junior-golf' || '17' == $post->post_parent )) {
    			echo '<script>{window.location.href = "https://www.bluegolf.com/junior/programs/nopgajr/index.html";}</script>';
    		} else {
    			echo '<script>{window.location.href = "https://www.bluegolf.com/pro/programs/nopga/index.html";}</script>';
    		}
    	}
    }
    add_action('wp_head','xmit_mobile_redirects');
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘What's the best way to redirect a single page for mobile devices?’ is closed to new replies.