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.