WordPress.org

Ready to get started?Download WordPress

Forums

What's the best way to redirect a single page for mobile devices? (15 posts)

  1. John
    Member
    Posted 10 months ago #

    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 http://lifebyjohn.com/schedule to http://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 http://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

  2. mesquite_murph
    Member
    Posted 10 months ago #

    Hi John,

    I'm testing WPtouch Mobile Plugin, see plugin description at http://wordpress.org/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.

  3. Scriptrunner (Doug Sparling)
    Member
    Posted 10 months ago #

    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).

  4. John
    Member
    Posted 10 months ago #

    @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 http://www.detectmobilebrowsers.com or WURFL, but I'm not sure what actual script to type.

    Can anyone else help by chance?

    Thanks!

  5. mesquite_murph
    Member
    Posted 10 months ago #

    One more suggestion for you, try http://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!

  6. John
    Member
    Posted 10 months ago #

    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? :-)

  7. Scriptrunner (Doug Sparling)
    Member
    Posted 10 months ago #

    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.

  8. Scriptrunner (Doug Sparling)
    Member
    Posted 10 months ago #

    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

  9. John
    Member
    Posted 9 months ago #

    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 http://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!

  10. Scriptrunner (Doug Sparling)
    Member
    Posted 9 months ago #

    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.

  11. John
    Member
    Posted 9 months ago #

    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('http://www.lifebyjohn.com/mobile-schedule');
    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!

  12. grijoti
    Member
    Posted 5 months ago #

    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!

  13. grijoti
    Member
    Posted 5 months ago #

    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 = "http://m.mysite.com";
    }
    //-->
    </script>";
    }
    add_shortcode( 'myjavascript', 'myjavascript_func' );
  14. mediacellar
    Member
    Posted 5 months ago #

    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 = "http://www.bluegolf.com/junior/programs/nopgajr/index.html";}</script>';
    		} else {
    			echo '<script>{window.location.href = "http://www.bluegolf.com/pro/programs/nopga/index.html";}</script>';
    		}
    	}
    }
    add_action('wp_head','xmit_mobile_redirects');
  15. erjdavis
    Member
    Posted 2 months ago #

    Here is a wordpress plugin that allows you to do what you're looking for - http://ultimate-wordpress-mobile-redirect.com/

    You can set the single page you want redirected and you can choose different redirects for every page/post.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.