How to set up an ad appear only on mobile or desktop version of a website

WordPress not for a long time a simple blogging platform. It allows us to develop from simple blogs with a minimalist design up to portals si Forums complex or even online shops blown, thanks Pluginacquis WooCommerce and other the E-Commerce which can be integrated into WordPress.

Except sites presentation of companies and the nonprofit which are supported by various entities, the "life" of a large website can only be supported from advertisement or products / services that it sell them. It is the same thing as with televisions that are supported solely by advertising.

Diversity can be listed devices are on an advertisement (banner) on a website, it forces it to be visible in the optimum, whether web page that is accessed from ad found mobile devices, tablet or desktop.

WordPress users who want certain advertisements or items to be visible only on the mobile version or only on the desktop version of a web page have a very simple WordPress feature.

How to set up an ad appear only on mobile or desktop version of a website

Function “wp_is_mobile"It helps us to force an element (an advertisement, in our case) to appear only when the website is accessed from a mobile phone Android, iOS or Windows Mobile.

Here's the code for an advertisement to be visible only on mobile:

<?php
if ( wp_is_mobile() ) {
	cod_reclama_sau element
}
?>

Another option is to put the code between PHP functions:

<?php if (wp_is_mobile() ) { ?>
cod_reclama_sau_element
<?php }?>

In this way, the creative code will only be visible to browsers identified as a mobile device.

In the scenario where we as a ad to be visible only on the desktop version of the web page, in front of “wp_is_mobile” will be put “!”, which will determine that the following content will be visible on all devices, except on the mobile version.

Example code:

<?php if (!wp_is_mobile() ) { ?>
cod_reclama_sau_element
<?php }?>

This way you can manipulate elements on a web page, depending on which device is accessed.

How to set up an ad appear only on mobile or desktop version of a website

About the author

Stealth

Passionate about everything gadget and IT, I write with pleasure on stealthsettings.com since 2006 and I like to discover with you new things about computers and operating systems macOS, Linux, Windows, iOS and Android.

Leave a Comment