A few weeks ago a client asked me whether it is possible to show a different homepage on mobile devices than on the desktop version (a redirect). I’ve written the following function and added this to the client’s themes functions.php.
This function adds a small script to the head section of the theme. The script checks if you’re on the homepage and if the width of your browser is 480px or smaller. In case both are true the web shop page is loaded, instead of the default homepage (see the code example above).
A great and simple function. But, what happens when the permalink or slug changes or the client wants to set another page as mobile homepage? Wouldn’t it be great if he is able to set the redirect in his WordPress backend? I figured this would be a great idea, so I developed the Genesis Mobile Redirect Plugin.
Genesis Mobile Redirect Plugin
The Genesis Mobile Redirect plugin allows you to select a page or a custom URL, which you can set as homepage for mobile devices. You set the redirect either for smartphone or for smartphone and tablet. You can also set your custom max width if you want to show the mobile homepage for example on smartphones in combination with iPad mini.
Neil says
Oh that’s good and possibly very timely.
This last week I experimented with serving mobile pages (initially just a different front page) using this code:
https://github.com/serbanghita/Mobile-Detect
I set up a frontpage.php template to call the mobile detect function.
Then used their code for ‘if is mobile and not tablet’ to include a mobile file ‘else’ to include the full size file.
It certainly works. However I’m also going to try your way now.
Thanks
Frank Schrijvers says
Hi Neil,
That’s a different approach, but also interesting.
Frank
Neil says
Thanks Frank.
Your code worked perfectly just now.
I wonder though if there are SEO and UX implications of sending a mobile user to a different page instead of the regular home page.
Cheers
Neil
Babette says
Love the change you did there! We’ve been struggling with one of our sites and this issue. Thank you…might just give us the motivation to switch the site to Genesis now. Love that theme!
Thx
G22 says
Hi your code work perfectly for the homepage in native language. I have a second mobile homepage with WPML in english. I’m getting the error that I cannot redeclare ‘wps_params’ if I add your function again for my english page.
Any idea to help me achieve the same thing for my english page? Thanks a lot for all your knowledge you’re sharing with us 🙂
Frank Schrijvers says
You cannot use a function twice. If you change the functions name ‘wps_params’ in the second function it should work.
ADESOYE Richard says
I DON’T JUST KNOW HOW IMMA THANK YOU ENOUGH!!!!!
I’VE HAD ISSUES WITH MY DESKTOP AND MOBILE WORDPRESS THEME BOTH NOT WORKING TOGETHER (THE MOBILE THEME SHOWS THE CODE ON THE HOMEPAGE FROM THE DESKTOP THEME…). AND I’VE CARRIED OUT MANY RESEARCHES WITH NO CHANGES, BUT I FINALLY GOT YOURS.
AND THIS LITTLE PIECE OF CODE SOLVED IT.
THANKS.