I found this little nugget in the WordPress Codex called wp_is_mobile(). It will detect the user browser’s agent and will return a true or a false if it’s a mobile device. This is helpful if you would like to customized code specifically for a mobile device. Let’s say you have a media player and you want it to have a specific width for desktops and another width for mobile devices. So, here’s the code to detect if it’s a mobile device.

<pre lang="php">
if ( wp_is_mobile() ) :
  $player_width = '270';
else :
  $player_width = '400';

You can then use the variable $player_width in your media player configuration to set the width of the player. However, if you read the Codex, it says that tablets are considered as mobile devices, which is perfectly fine for my purposes here. It’s ok to use this tiny little function in your WordPress templates, but it’s not recommended for media queries.