Mobile page served for Ipad
-
Hello support team,
I’m using your plugin proudly, i noticed that the mobile page is also served for Ipad.
I tried to install third party plugins to solve this problem, but this does not work.
Can you please help me to solve this problem ? thank you.
The page I need help with: [log in to see the link]
-
Hello again
I’m actually talking about the home page.
Thank you
Hi @khalilbeat, thank you for opening a thread.
This plugin uses the WordPress core function wp_is_mobile to detect if the device is mobile or not a mobile.
Here you will find more details about this function: https://developer.www.ads-software.com/reference/functions/wp_is_mobile/
This function doesn’t distinguish between mobile phones and tablets.
Tablets are treated as mobile devices.The goal is to give the possibility to replace content to give less load to the mobile devices, including tablets.
Usually, these devices have a lower powerful CPU than a desktop. In these cases, it’s better to serve lighter content.However, you can filter the output of the function wp_is_mobile and exclude the iPad and tablet.
Try adding this code in your functions.php:
function my_exclude_ipad_and_tablets( $is_mobile ) { if( false !== strpos( $_SERVER['HTTP_USER_AGENT'],'iPad' ) || false !== strpos( $_SERVER['HTTP_USER_AGENT'],'tablet' ) ){ return false; } return $is_mobile; } add_filter( 'wp_is_mobile','my_exclude_ipad_and_tablets' );
I haven’t tested it, but it should work.
Be just careful with the cache. If you have a plugin for the cache, it has also to distinguish between mobile phones and tablets, in another case when the cache is created visiting a page with a mobile device, then with the tablet you will see the same cached page.I hope it helps. Maybe in the future, I will add the possibility to exclude specific devices via the options, but it will not be very soon.
Thank you Jose !
A tried your code but didn’t work.
I have caching plugin that i turned to off to test, and still same result.
Still dont understand.
When i turn off your plugin, it works and serve me the desktop page not the mobile one.
Do yo have other suggestions ?
Thank you for helping
You are welcome @khalilbeat
Deactivating SCFM, all works as normal. The normality is that on the tablet you see the same version as on desktop.
If you activate Specific Content For Mobile the tablet is considered as a mobile device, but adding the suggested code, the tablets having the user agent including in that code will be considered as not mobile devices.
Probably there are tablets that don’t send the user agent written in the previous code.
Try adding a couple of user agents, and checking on lower cases letters:
function my_exclude_ipad_and_tablets( $is_mobile ) { if( false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'ipad' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'tablet' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'playbook' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'mobi|opera mini' ) ){ return false; } return $is_mobile; } add_filter( 'wp_is_mobile','my_exclude_ipad_and_tablets' );
If in your case it still doesn’t work, do the following:
– enable the debug adding this to your wp-config.php file:
define('WP_DEBUG', true); define( 'WP_DEBUG_LOG', true );
(read here for more details: https://codex.www.ads-software.com/WP_DEBUG)
– in the suggested function add this line to detect the user agent:
error_log( ‘User agent: ‘.$_SERVER[‘HTTP_USER_AGENT’] );
– open the file wp-content/debug.log and check the user agent of your tablet. Then post what you have found.
The final code will be this:
function my_exclude_ipad_and_tablets( $is_mobile ) { error_log( 'User agent: '.$_SERVER['HTTP_USER_AGENT'] ); if( false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'ipad' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'tablet' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'playbook' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'mobi|opera mini' ) ){ return false; } return $is_mobile; } add_filter( 'wp_is_mobile','my_exclude_ipad_and_tablets' );
I’ve tested the code above on some tablets, and it works.
Do all the tests always without cache.
Thank you Jose for the help.
It’s actually still not working.
I’m testing it under an Ipad pro.
Do you think apple Ipad Pro have a specific user agent ?
Thank you again.
Hi Jose,
I maybe have some good news ..
It actually works when i use safari under my Ipad pro.
But it still not working in chrome.
This mean that maybe the plugin detect google chrome as mobile from ipad.
I got the idea from this page : https://www.tinywp.in/wp_is_mobile-exclude-ipad/
What do you think ?
Thank you
Hi @khalilbeat, you are welcome.
I don’t think it has a specific user agent, but if you want to know the user agent, add the line suggested in my previous comment and enable the debug mode.
Are you sure the custom function is being called?Putting error_log( ‘User agent: ‘.$_SERVER[‘HTTP_USER_AGENT’] ); inside the function you will not only see the user agent in the debug.log file, you will also understand if the function is called.
Did you read this :
Hi Jose,
I maybe have some good news ..
It actually works when i use safari under my Ipad pro.
But it still not working in chrome.
This mean that maybe the plugin detect google chrome as mobile from ipad.
I got the idea from this page : https://www.tinywp.in/wp_is_mobile-exclude-ipad/
What do you think ?
Thank you
Hi @khalilbeat
yes I have read it after my last comment.
Changing browser you should have in any case the string “ipad” in the user agent variable if it’s a tablet.
I would do what suggested in my previous comment and being sure you don’t have problems with the cache.
First of all, you have to be sure that that function is called, and then that it works.
Hi Jose,
I followed step by step and added the debug code and the error log too.
How can i be sur that the function is called ?
Thank you
first of all, check the debug is working and that the file where you have put that function is called.
In the end of the file where you have put that function, add this line of code:
error_log( ‘Debug is working’ );
If you don’t see “Debug is working” in wp-content/debug.log, it means one of these two things:
– the debug mode is not working
– that file is not calledIf you see “Debug is working” in wp-content/debug.log, we can go ahead.
In witch file i need to add : error_log( ‘Debug is working’ ); ?
I tried functions.php = eror
wp-config.php = wiebsite not loading ?
I don’t see any wp-content/debug.log file in my rool folders ..
Thank you ??
Please do exactly as follow:
– open functions.php and put this code:function my_exclude_ipad_and_tablets( $is_mobile ) { error_log( 'User agent: '.$_SERVER['HTTP_USER_AGENT'] ); if( false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'ipad' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'tablet' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'playbook' ) || false !== strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'mobi|opera mini' ) ){ return false; } return $is_mobile; } add_filter( 'wp_is_mobile','my_exclude_ipad_and_tablets' ); error_log( 'debug is working' );
– Open wp-config.php and put this code just before the comment /* That’s all, stop editing! Happy blogging. */
define('WP_DEBUG', true); define( 'WP_DEBUG_LOG', true );
– Load the page you are investigating without cache. If the cache is active, you will not see anything in debug.log
– Check the presence of the file wp-content/debug.log
– Open wp-content/debug.log and look for the comments User agent: … and “Debug is working”If you don’t see wp-content/debug.log or you don’t see “debug is working” inside debug.log, it means one of these things:
– The debugging is not working
– The file functions.php is not called
– You have cache activeIf the debugging is not working you can read more details here: https://codex.www.ads-software.com/WP_DEBUG
If you want to be more sure the page is not served by cache, you can add a query argument to the URL, e.g. https://biblito.com/?no_cache=true
If the file functions.php is not called, and your are sure that theme is active, it means the page is served by cache. If functions.php exists, it’s always called.
Or you have a fatal error before the parser can arrive to the line error_log( ‘debug is working’ ); But in this case you should notice it.-
This reply was modified 4 years, 9 months ago by
Jose.
I followed step by step your recommendations.
I actually dont see debug.php.
Maybe my hosting provider do not create the WordPress debug.log.
If so, i need to call them tomorrow.
Thank for all,
Hi @khalilbeat I don’t know if you have read my last comment, and what version you have read. www.ads-software.com went down while I was editing my comment and then it went for moderation, probably for the links.
@moderator: I think WordPress should improve a little the comment spam detection.
The first link is a link to the codex (WordPress server), the second one is a link to the page @khalilbeat has asked help for.
It’s not the first time this kind of thing happens, a lot of comments of mine are detected as spams, only because I link codex pages or the page of who is asking support. Who is responsible for the spam detection system? Can it be improved?Now I don’t know what comment he has read.
@khalilbeat Hoping the moderator approves my last comment, I suggest reading it before contacting your hosting provider.
Be sure you have copied also error_log( ‘debug is working’ ); from the suggested code. -
This reply was modified 4 years, 9 months ago by
- The topic ‘Mobile page served for Ipad’ is closed to new replies.