Connect with us
Padiwise Banner


How to Display Content for Mobile or Desktop Only Using WordPress



How to Display Content for Mobile or Desktop Only Using WordPress

This WordPress snippet will use WordPress built-in “mobile detect” function “wp_is_mobile” to create a simple shortcode that can hide certain parts of your content from mobile visitors and-/or desktop visitors.

Did you know that you can use WordPress built-in “mobile detect” function wp_is_mobile to create a simple shortcode that can hide certain parts of your content from mobile visitors and-/or desktop visitors. The wp_is_mobile function returns true when your site is viewed from a mobile browser. Using this function you can create adaptive-/responsive WordPress themes based on visitor device.

Method 1 instructions
Simply use IF conditions in your templates.

/* Ofofonobs Developer... */<?php if( wp_is_mobile()){ ?> 
<span>mobile stuff goes here</span>
<?php } else { ?> 
<span>desktop stuff goes here</span>
<?php } ?>

Method 2 instructions
This snippet will allow you to use shotcodes the [desktoponly] desktop content [/desktoponly] or [mobileonly] mobile content [/mobileonly] to determine what content should be returned to the visitor.

Add this code to your functions.php

/* Ofofonobs Developer... */<?php 
// [desktoponly] shortcode // 
add_shortcode('desktoponly', 'wp_snippet_desktop_only_shortcode'); 
function wp_snippet_desktop_only_shortcode($atts, $content = null){ 
if( !wp_is_mobile() ){ return wpautop( do_shortcode( $content ) );
} else { 
return null;
// [mobileonly] shortcode // 
add_shortcode('mobileonly', 'wp_snippet_mobile_only_shortcode'); 
function wp_snippet_mobile_only_shortcode($atts, $content = null){ 
if( wp_is_mobile() ){ return wpautop( do_shortcode( $content ) );
} else { 
return null;


Disclaimer: We sell any type of script/themes/plugins, we also offer web design/developement, graphics design, SEO, Social media followers, VTU Platform and more. visit our contact page to get in touch with us or WhatsApp (+234) 08114313795.
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Entertainment1 week ago

Purple Speedy Loses 7.8 Million Followers on TikTok As Her Account Get Suspended 

Nigerian Tiktoker and dancer , Purple Speedy, known for her contagious energy and trendsetting dance moves, finds herself in the...

Entertainment2 weeks ago

5 Benefits of Buying Gold Bars in an Economic Downturn

It’s estimated that 10.8% of Americans own gold. It shouldn’t come as a surprise that the precious metal we’ve used as currency...

Entertainment2 weeks ago

How Will Unemployment Benefits Affect My Taxes?

How are you coping with unemployment? In economic uncertainty, many individuals rely on unemployment benefits. This financial lifeline helps cover...

Entertainment2 weeks ago

6 Essential Questions to Ask Your Interior Renovation Contractor

Embarking on an interior renovation project can be exciting, but it also comes with the responsibility of ensuring the job is done...

Entertainment2 weeks ago

The Benefits of Using a VA Back Pay Calculator

Are you a veteran who wants to make sure you receive the full amount of your VA benefits? Look no...

Entertainment2 weeks ago

10 Things To Know About Big Brother Naija All Stars Winner, Ilebaye

Meet Ilebaye Precious Odiniya, the victorious Big Brother Naija All Stars winner, who emerged triumphant in the reality TV show,...

Entertainment2 weeks ago

What You Need To Know About Keke Wyatt’s World, A New TV Series On We tv

In an exciting announcement last Wednesday, the network revealed Keke Wyatt’s World, a captivating series starring the talented singer-songwriter and...

Entertainment2 weeks ago

100 of the Most Expensive Dog Breeds in the World

Did you know that some dog breeds are known to come with a hefty price tag? These luxury and exclusive...

Entertainment3 weeks ago

How to Get Rich as a Woman: The Ultimate Guide

Getting rich is a dream of millions of people across the United States, and building wealth starts with learning and...

Entertainment3 weeks ago

25 Highest Paying Jobs in America in 2024

Everyone is always looking to earn the most money possible when it comes to their hourly jobs or full-time careers....