Disable WP Background Image on Mobile Devices

If you have a WordPress blog and many of your visitors view your site using a mobile device, you may want to disable your Theme’s Background Image when a user views your page on a mobile device. Most mobile users usually don’t have excellent connectivity and are connected through slow networks. Add that to the fact that most mobile internet plans are billed by the amount of data consumed. Your mobile visitors would thank you for it. Another good reason is that with smaller screens, the background image is rarely displayed properly or just covered up by the content.

To disable the Background Image functionality when a site is being viewed through a Mobile Device, add the code below on your child theme’s functions.php

add_action( 'after_setup_theme', 'ra_remove_mobile_bg_image', 11 );

function ra_remove_mobile_bg_image() {
   if ( wp_is_mobile() && !is_admin() && !is_customize_preview() ) {
      remove_theme_support( 'custom-background' );
   }
}

The code only affects the front-end of the website. If an admin is managing the site using a mobile device then the Background Image functionality would still be available to him or her. This code will probably have no effect if you are using page caching, unless the caching plugin that you use can differentiate between desktop and mobiles.

Share This Post

1 Comment

Add a Comment
  1. Very nice tip Ron. It makes things faster

Leave a Reply

Please write your comments in english. I delete anything that even remotely resembles spam.

Note: When posting code, enclose it in pre and code tags.
e.g. <pre><code> Add code here </code></pre>