Advertise Here

WordPress wp_is_mobile() serves as: Is it still useful?

by | Dec 26, 2024 | Etcetera, wordpress maintenance, wordpress seo | 0 comments


wordpress Fashion 3.4 was introduced throughout the spring of 2012. In addition to introducing the Theme Customizer and the ability to automatically embed Tweets, Fashion 3.4 also added a feature that developers could simply use to check whether a website buyer once connected from a mobile system such as a smartphone or a tablet.

That function – wp_is_mobile() – appeared at a time when the famous “Retina Display” presented by Apple for its iPhone 4 had a resolution of 640 x 960 pixels. When the iPhone 5 arrived a few months after wordpress 3.4, the phone’s display reached 640 x 1,136 pixels, however some distance from the presentations of recent smartphones and tablets, which blur the tracks between the precise resources of the mobile screen and the desktop computers.

That’s how it is wp_is_mobile() of any use at the moment?

The purpose of the wp_is_mobile() function

In 2012, strengthening the browser for CSS media queries that enabled responsive web design was relatively new, however. (To tell the truth news for users of Microsoft’s Internet Explorer browser!) Also, enabling web page layouts that fit many viewport sizes was not the service at the time wp_is_mobile().

The feature does not distinguish between phones and pills and is completely blind to the pixels available in the buyer’s browser. Alternatively, wp_is_mobile() it was once conceived as a tool that could allow developers to optimize bandwidth when responding to mobile devices that were often underpowered and possibly in the hands of consumers who paid their telecom providers for information transfers.

With phones and tablets currently more durable than many desktops available in 2012, bandwidth throttling may be much less vital, alternatively however there are use cases for a feature that simply splits the sphere in two: mobile devices and all the rest other.

The wp_is_mobile() function in motion

The wordpress wp_is_mobile() the function returns true when obtained as a result of a request from browsers in most smartphones and tablets (alongside the Kindle). So, the ancient example of the function that generates several streams of content material in PHP looks like this:



    

This content material subject material is for cell devices

This content material subject material is for desktops (and laptops).

If you actually want to optimize your website‘s output for mobile devices (most certainly to minimize bandwidth requirements), the above technique could be used in theme files to produce completely different structures for mobile and desktop pages.

Detection of tools for granular content subject material adjustments

CSS media queries and alternative ways that support responsive web design can agree that Internet web page layouts adapt to a wide variety of computer screen sizes and orientations. Then again they can’t imply that you will be able to do this be in touch along with your website visitors such as mobile or desktop shoppers.

For example, you know that desktop shoppers will use the mouse to “click” on elements of your Internet website, while mobile shoppers will “tap.” Desktop shoppers may “right-click” a link to begin opening the link in a new browser window. Meanwhile, cell phone buyers might “push and hold” to start the same business. Simply talking to buyers about how to navigate your website (such as in your agreement documentation) may simply indicate that you are using the fallacious terminology section at that time.

That’s right, that’s how we’ll be able to combine wp_is_mobile() and wordpress shortcodes to strengthen the granular output of mobile or desktop content material in a way that is additionally easy to command for website publishers.

We will be using mobile/desktop detection alongside wordpress add_shortcode() AND do_shortocde() functions to create shortcode apparatus editor can be applied in posts.

First we will add this code to our theme purposes.php file (after protecting it by creating a children’s theme):

/**
 * Add shortcodes
 */

// Create [desktop] shortcode
add_shortcode('desktop', 'show_desktop_content');
function show_desktop_content($atts, $content material subject material = null){
    if( !wp_is_mobile() ){
        return do_shortcode( $content material subject material );
    } else {
        return null;
    }
}

// Create [mobile] shortcode
add_shortcode('cell', 'show_mobile_content');
function show_mobile_content($atts, $content material subject material = null){
    if( wp_is_mobile() ){
        return do_shortcode( $content material subject material );
    } else {
        return null;
    }
}

This creates the [desktop] AND [mobile] shortcodes (and their end tags) that we may use in any published material or in any web page content such as this:

Password Be in agreement

To switch your password, [desktop]click on on[/desktop][mobile]tap[/mobile] the cog icon.

On a cellular system, the contents of the object above will look like this:

Mobile shoppers will see “tap” throughout the output above.

On all other devices, visitors will see the following:

“Desktop” buyers will see “click” throughout the output above.

The program makes it reasonably easy to send content material that is “aware” of how visitors interact with your wordpress internet website.

wordpress-caching”/>The wp_is_mobile() function and wordpress caching

You don’t want to use wordpress since 2012 to grasp that caching web pages is probably one of the best tactics for strengthening power. On the other hand, basic wordpress caching can create problems when trying to send different content material on requests for the same Internet web page.

A wordpress cache of a single Internet web page is initiated via a client request. If the first request comes from a cellular system, the cached content material will also be personalized for cellular buyers if modified via wp_is_mobile(). And each subsequent request for that Internet web page will send subject matter, cellular content material — even to desktop buyers — until the cache is cleared.

That’s why Kinsta’s controlled wordpress web hosting platform helps separate caches for mobile and desktop content, starting with the local cache on your NGINX Internet server and extending to Kinsta’s Edge Cache in more than 260 Cloudflare PoPs across the industry.

Enabling page caching for mobile devices is accomplished with just a couple of clicks (or taps!) in the MyKinsta dashboard:

Screenshot showing the caching controls within the MyKinsta dashboard. Visible is the option to disable or enable floating cache.
Cache controls for a wordpress website within the MyKinsta dashboard.

Summary

The wordpress feature wp_is_mobile() it might seem like a blast from the former, alternatively, you want to look for uses for its “mobile or desktop” tracking that help you create a better experience for all your website visitors.

Don’t forget that you will simply need separate caches for the opposite content material you generate if you want to get the best power from the cellular and desktop paths.

You will have an actually higher idea to take advantage of wp_is_mobile()? Please let us know through the statement below.

wordpress publishing wp_is_mobile() serves as: Is it still useful? appeared first on Kinsta®.

WP hosting

[ continue ]

wordpress Maintenance Plans | wordpress hosting

Read more



wordpress-wp_is_mobile-serve-as-is-it-nonetheless-helpful/”>Source link

thatguy
Author: thatguy

Places

Services

  • No Categories

Classifieds

  • No Categories

Events

News

Shopping