wp_is_mobile. How to reveal the status of the Gutenberg block via

Good morning everyone I’m looking for some suggestions for creating a script/plugin that does basically this (in a Gutenberg environment): the wp_is_mobile function, a condition for publication of a block depending on the device.

The most common use might be: Create two cover blocks, one for desktop and one for mobile.

There are dozens of plugins out there to achieve this, but not all of them, via css display: block one by one or the other depending on the user’s device. This solution is not efficient as the hidden image is still loaded in the browser which is penalizing the user and slowing down the site (pagespeed).

I found a paid plugin that talks about server-side mobile situations in general but does 200 other things I honestly don’t care about.

Finally, I found another plugin I’m currently using using Mobile Blocks by PootlePress, which doesn’t actually just use wp_is_mobile, but regular expressions that intercept mobile device user agents (but, as a WordPress feature) Unlike tablets, not tablets) and display the block made for it. them. The issue is that it crashes sometimes and that is, it triggers the mobile version on the desktop (especially on cached or highly optimized sites) and doesn’t update very often.

That’s why I was wondering how to create a hand-built, ready-to-use solution. The first solution I came up with is to use a plugin like lazy block, acf block etc and create a custom block with two images that are activated via php and the wp_is_mobile function (one or the other). However, I still have to install additional plugins for this simple (to say, but not to do) activity. Another approach would be to parse all blocks with parse_blocks(), and use wp_is_mobile to display a certain cover block instead of another. The point is that even this solution doesn’t work for me.

And so I thought I’d be here asking advice from people who know more than me, some suggestions, alternative approaches! Thank You!!!

Leave a Comment