- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hello, I’m using wordpress and trying to redirect users on a mobile device from a single page to another page. I’m only doing it for one page so I don’t require a full plugin.
Here’s what I’m plugging into my functions.php:
function welcome_mobile_redirect() {
if (is_mobile() && get_the_ID() == 1114) {
wp_redirect('http://necronomicon.studioissa.com/welcome/');
}
}
But it’s not working yet. Any thoughts?
get_the_ID
can only be used within a WordPress Loop. If you need to get the ID outside, check out this.
But I would handle this differently by:
page-{id}.php
No need to check for current state from your functions on every load. Corresponding template will only load when that page loads so we off load that responsibility.
So your final code would be
$url = 'http://necronomicon.studioissa.com/welcome/';
if ( is_mobile() ) wp_redirect( $url, 301 ); exit;
Hi Alen,
Thanks so much. I’m already using a custom template for that page. But when I put this code in it doesn’t work.
Does this code need to be anywhere specific?
Thanks!
Sorry that should be wp_is_mobile
not is_mobile
.
so,
$url = 'http://necronomicon.studioissa.com/welcome/';
if ( wp_is_mobile() ) wp_redirect( $url, 301 ); exit;
Here is a plugin that would allow you to accomplish this – http://www.ultimate-wordpress-mobile-redirect.com
The plugin allows you to set a unique redirect URL for every page and post on your wordpress website. It works for mobile and tablets.
Hope that helps!