Time for action—removing a widget using PHP
Let's look at how we can use PHP to hide a widget.
First, let's find the code for the three images. This is contained within a widget area, which we can see by accessing the Widgets screen, as shown in the following screenshot:
So, what we need to do is remove that widget area from mobile devices. We can do this in one of the following two ways:
By adding a conditional function around the code for the widget area in the
header.php
fileBy adding a conditional function to the widget itself with the addition of another plugin, called Widget Logic
We're going to use the second method as it means we don't remove the entire widget area, just this widget. Perform the following steps:
1. First, let's install and activate the Widget Logic plugin. We can find this at http://wordpress.org/extend/plugins/widget-logic. On the Plugins screen, we will click on Add New, then search for the Widget Logic plugin and click on Install. Once it's installed, we will click...