Conditional output - depending on device type

Hello!

Im trying to switch from manual PHP coding + ACF to Bricks, and i have a question regarding the Conditional Loading of some elements, depending on the device.

Example:
a lot of times i have to create a Hero Slideshow for desktop, but display only a single image on mobiles, to speed up the loading times.

Until now, i successfully used the Mobile Detect PHP Class: http://mobiledetect.net/ to detect the device type and load different codes for each device.

i used something like this:

if ( $detect->isMobile() ) {
include code for mobile devices
}else:{
include code for tablet & desktops
}

Can this be achieved with the new conditions function in Bricks? Unfortunately this is very important for me and i cant figure it out:(

Note: i dont want to hide and show Elements with display: none and block - i need to load the correct code for the user device.

any help is highly appreciated!

thank you and best regards,
andi

2 Likes

Hi Andiszek, I have the same problem.
Did you manage to solve?

Hi Guys, perhaps this thread can be useful for you:

2 Likes

hello @HeroRox
unfortunately the wp_is_mobile() function also includes tablets, so its not a big help:(

@chuvadigital
i found a solution, which seems to work after a few tests.

Step 1:
download and install the Mobble plugin:

this hasnt been updated in many years, but its still usable.

Step 2:
download the latest Mobile Detect version from here: http://mobiledetect.net/
copy the Mobile_Detect.php file to the mobble folder, overwriting the old file

in Bricks, select a section, go to Conditions → Dynamic Data:
{echo:is_mobile} == 1
shows the section on mobiles ONLY

{echo:is_mobile} != 1
shows the section on everything (including tablets), except the mobile devices

here you can see the entire list of available functions:

lines 437-485

i have only tested is_mobile() and is_handheld(), and both work well.

hope it help!
regards,
andi

3 Likes

It helped a lot, it worked here for me. Grateful

1 Like

Hi @andiszek

I have followed your instructions. I downloaded Mobile-Detect-3.74.0.zip but inside the folder there will be a file: MobileDetect.php.
Not the file Mobile_Detect.php

The structure is similar but will have different code. & when changing the file content in the wordpress plugin. The website has an error.

Can you check again?
Thankful!

I found a similar plugin:

Use wp_is_mobile() instead of {echo:is_mobile} .

Everything works perfectly.