scottsweb / mobble

✅ WordPress plugin that provides conditional functions for detecting a variety of devices.
http://scott.ee/journal/mobble/
Other
85 stars 19 forks source link

mobble

mobble

About

mobble provides mobile related conditional functions for your site. e.g. is_iphone(), is_mobile() and is_tablet().

CSS media queries are great for creating responsive web designs but they do not always provide enough control. There are times when not all of the content, JavaScript or CSS on a page is relevant for a particular device. With the mobble functions you can make these kind of tweaks to your theme.

mobble can also add device information to the body class of your theme allowing you to easily target your CSS for different gadgets.

Installation

To install this plugin:

Visit WordPress.org for a comprehensive guide on in how to install WordPress plugins.

Hooks & Filters

...

Frequently Asked Questions

What functions are available?

The most useful ones are:

<?php
is_handheld(); // any handheld device (phone, tablet, Nintendo)
is_mobile(); // any type of mobile phone (iPhone, Android, etc)
is_tablet(); // any tablet device
is_ios(); // any Apple device (iPhone, iPad, iPod)
?>

You can also use:

<?php
is_iphone();
is_ipad();
is_ipod();
is_android();
is_blackberry();
is_opera_mobile();
is_symbian();
is_kindle();
is_windows_mobile();
is_motorola();
is_samsung();
is_samsung_tablet();
is_sony_ericsson();
is_nintendo();
?>

Inspecting Mobile_Detect.php will also reveal some other useful tools.

Do you have any examples?

Yup. This first example disables the sidebar for mobile/phone devices:

<?php
if (!is_mobile()) {
    get_sidebar();
}
?>

This second example loads a specific stylesheet for Apple devices (iPhone, iPod and iPad):

<?php
if (is_ios()) {
    wp_enqueue_style('ios', get_template_directory_uri() . '/ios.css');
}
?>

Caching

Please note that in certain setups caching will cause undesired behaviour. If your cache is set too aggressively PHP will be skipped and the device detection will not work.

Changelog

1.6

1.5

1.4

1.3

1.2.1

1.2

1.1

1.0