- This topic has 10 replies, 3 voices, and was last updated 3 years, 4 months ago by
melvin.
-
AuthorPosts
-
July 6, 2021 at 6:05 pm #1847124
Ian
Hello, I’ve followed another thread by Tom and added this snipped to my website thelitunderground.com
However, it is no redirecting on mobile. Am I missing a step? Thanks!
add_action( ‘wp’, ‘tu_redirect_mobile’ );
function tu_redirect_mobile() {
if ( wp_is_mobile() AND is_front_page() ) {
wp_redirect( ‘https:/thelitunderground.com/podcasts’, 301 );
exit;
}
}July 6, 2021 at 9:35 pm #1847207Elvin
StaffCustomer SupportHi Ian,
can you try this instead?
add_action( 'wp', 'tu_redirect_mobile' ); function tu_redirect_mobile() { if ( wp_is_mobile() && is_front_page() ) { wp_redirect( 'https://thelitunderground.com/podcasts', 301 ); exit; } }
Let us know how it goes.
July 7, 2021 at 11:08 pm #1848454Ian
Hey Elvin, that one didn’t end up working.
July 7, 2021 at 11:23 pm #1848461Elvin
StaffCustomer SupportIt’s working on my end.
You can visit this page – https://dev-generate-press.pantheonsite.io/
When I visit this page on my Android phone (chrome), I get redirected to your site’s podcasts page.
It should be the same when you try to visit it from your phone’s browser.
Note: I don’t think this kind of redirection is reliable though. Even the official documentation doesn’t recommend this – https://developer.wordpress.org/reference/functions/wp_is_mobile/ – WordPress core’s
wp_is_mobile()
is not reliable. It’s better to rely on JS for this.Consider trying this:
Create a Hook element. Set the display rule location to “Front page” and then add this code.
<script> if( /Android|webOS|iPhone|iPad|Mac|Macintosh|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { location.href = "https://thelitunderground.com/podcasts"; }</script>
This should redirect the visitor to the href specified. If the page visited on a detected mobile device specified on the condition.
July 8, 2021 at 1:32 pm #1849289Ian
Thanks for the help Elvin! I just added a hook, set a rule to the front page and added the code. Is it working on your end? It isn’t working on my phone.
July 8, 2021 at 7:09 pm #1849427Elvin
StaffCustomer SupportThanks for the help Elvin! I just added a hook, set a rule to the front page and added the code. Is it working on your end? It isnāt working on my phone.
It’s working on my end when I visit your site. On my phone (Android, Chrome), when I try to visit the frontpage, it brings me to the /podcasts/ page immediately.
July 10, 2021 at 11:32 am #1851184Ian
Hey Elvin, so I see that its working for Android on Chrome. However, it is not working for Safari on Iphone on the phones around my house. Thanks!
July 10, 2021 at 11:05 pm #1851396Ian
It’s working now! Thanks Elvin!
July 10, 2021 at 11:05 pm #1851397Ian
REsolved
July 11, 2021 at 9:40 pm #1852304Elvin
StaffCustomer SupportNo problem. Glad to be of any help. š
April 30, 2022 at 11:22 am #2205062melvin
Dropping by to say thank you for the reliable guide.
I used hook with js method
Thanks Alvin
-
AuthorPosts
- You must be logged in to reply to this topic.