Conditional Tags Worpress for mobile devices

Asked

Viewed 34 times

0

How do I use a Conditional Tag in my wordpress theme so that a certain script is not loaded on mobile devices. There is such a tag?

If there could show me an example?

In this example the script would only load at the home of the site, I would like a code that when checking that the device is mobile the script would not load. or even appear in the source code.

 <?php if( is_home() ): ?>

 <script data-cfasync="false" type="text/javascript" src=""></script>

 <?php endif; ?>

1 answer

1

Use the function wp_is_mobile():

<?php
if ( wp_is_mobile() ) {
    /* Display and echo mobile specific stuff here */
}
?>

This function is present in Wordpress since version 3.4. See more details about the function on Codex.

  • But what makes this conditional? I need some scripts not to be loaded on mobile devices

  • It checks if it’s on a mobile device, so you can check and make sure that it doesn’t load your files on Movies devices.

  • shows an example of what the code would look like

  • This condition is not fine-tuned, a php library can be good: http://wordpress.stackexchange.com/a/46838 - if you want to test and include in the answer, feel free :)

  • I think the @user3192159 question is easily answered by translating the comment that is in English...

  • Folks don’t seem to understand the question, I simply want certain script not to be loaded on mobile devices only on desktop it would be executed

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.