Suppressing Sidebar Ads on Mobile in WordPress

This guide provides instructions for suppressing your standard sidebar ads when your WordPress site is viewed on mobile devices.

Suppressing ads on mobile pageviews may be needed to improve viewability if you have a responsive single-column theme on mobile devices, causing the sidebar ads to load below the content, or if your site displays a desktop version of the site on mobile, requiring users to zoom in to read the posts, forcing your sidebar out of view.

Look over the available methods and consider which method is the most appropriate for your site. If you’re unsure or need assistance, please contact us at support@shemedia.com for technical assistance.

Restrict Widgets Plugin Method

This method is useful for suppressing any ads that are stored in widgets. It will NOT work for any ad code that is installed in hooks or directly in theme files. If you have ads in hooks or theme files, you’ll want to use the shortcode method described below.

1. In your WordPress dashboard, go to Plugins – Add New and type “Restrict Widgets” in the search box. Then click Search Plugins.

2. Follow the instructions to install and activate the Restrict Widgets plugin.

3. In your WordPress dashboard, go to Appearance – Widgets and open a widget that has your SHE Media ad code. You’ll see two new drop-down boxes under the text “Display / Hide Widget.” Make sure the top drop-down box is set to Hide widget on selected.

4. In the second drop-down box, scroll down and select Mobile under Devices. Then save your changes to the widget.

5. Repeat these steps for any other widgets with SHE Media ad code you want to suppress on mobile devices.

6. Once you’ve made these changes, you may need to clear your site’s cache if you have a caching plugin.

If you have any questions or problems, please contact us at support@shemedia.com for technical assistance.

Widget Logic Method

If you already have the Widget Logic plugin installed, this method might be the easiest method since it requires no additional plugins or changes to your theme files.

To limit any SHE Media ads in widgets from loading on mobile devices, you’ll open the widget and add this code to the Widget Logic field:

! wp_is_mobile()

If you already have code in that field to keep your SHE Media ads from showing on sponsored posts, you’ll add the code above in front of the code already in place, with && added between them like in this example:

! wp_is_mobile() && ! (is_single() && in_category('140'))

If you have any questions or problems, please contact us at support@sheknows.com for technical assistance.

WordPress Shortcode Method

NOTE: If you do not feel comfortable altering your WordPress theme files, do not attempt this and contact your designer or the Helpdesk for assistance. We also recommend backing up your files before making this change. Be sure you know your cPanel login – any errors inserting code into your functions.php file could result in making your site temporarily unavailable until you correct them via your cPanel access.

1. In your WordPress dashboard, go to Appearance – Editor and click on the functions.php file to open it for editing.

2. Scroll to the bottom of the file and press enter to create a blank line after all other code. Then paste in the following code and click Update File:

/** Add shortcode to hide elements in mobile */
add_filter('widget_text', 'do_shortcode');
function not_mobile_shortcode($atts, $content = '') {
if (wp_is_mobile() === true) {
$content = '';
}
return $content;
}
add_shortcode('not_mobile', 'not_mobile_shortcode');

3. To remove an ad code from mobile device pageviews, surround the ad code with the [not_mobile] [/not_mobile] shortcode, like this:

[not_mobile]
YOUR AD CODE HERE
[/not_mobile]

This will prevent anything between the shortcode tags from being sent to the browser on mobile devices. You can use this shortcode for ads installed in widgets, hooks, or directly in theme files.

4. If your ad code is stored in a hook (for Genesis, Thesis and some Headway themes), be sure to check the “Execute Shortcodes on this hook” check box and save your changes or this will not work.

5. Once you’ve made these changes, you may need to clear your site’s cache if you have a caching plugin.

If you have any questions or problems, please contact us at support@shemedia.com for technical assistance.


Previous
Previous

Viewability Guide

Next
Next

What is the Difference Between CPM Vs. RPM?