I just read the wp_is_mobile function reference and I have some questions. As you can read, there is a line explanation in bold text: It also should not be used for themes. I excactly don't know what it's mean. I just want to implement this in a theme which is combined with css media query for the layout and wp_is_mobile for removing some element.
For example, I want to display slider and sidebar in large window (i.e. desktop) then I want to remove them in mobile device. I can hide them with css propery display: none; visibility: hidden
. But I wonder if they're still rendered. In related to the bold line warning above, when and where I must use that function? Ok, I got an idea. How if I create a simple conditional check like this line?
<?php
if ( wp_is_mobile() )
{
get_template_part( 'mobile-content' );
} else {
get_template_part( 'content', get_post_format() );
}
?>
First, it checks if the mobile device detected, then my custom template will be rendered mobile-content.php
. Otherwise it will render normal template content-{post-format}.php
.
Please share your opinion which is the best way to implement wp_is_mobile
and combine it in media query. Hope you can get my point.
Best regards.
wp_is_mobile()
function does consider tablet as a mobile device. So the use of this function in a theme is not recommended. – Domain Jun 25 '15 at 9:47wp_is_mobile()
is extemely unreliable and a function that should have never made it into core. It relies on user agent which can be manipulated. If the function fails, the incorrect info is displayed to the incorrect device. Your best solution is to use responsive design – Pieter Goosen Jun 25 '15 at 9:52wp_is_mobile()
have pros and cons. If I only use media queries, it makes all elements and contents rendered like normally and I think it wasn't reducing page load. Cmiiw – learn4life Jun 25 '15 at 10:09