Hello,
I am having trouble making a conditional view for desktop and a conditional view for mobile. I have tried using wp_is_mobile() and am not having much luck.
Do know a work around?
Thanks,
Cam
Hi Cam,
Thank you for contacting us and I'd be happy to assist.
During testing on my website, I was able to use the "wp_is_mobile()" function, in the conditional block, by following these steps:
1. I registered a custom shortcode, that returns '0' if the "wp_is_mobile()" function returns false, and '1', if it returns true:
add_shortcode('is-mobile', 'is_mobile_func');
function is_mobile_func() {
if( !wp_is_mobile() ){
return '0';
} else {
return '1';
}
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
2. Next, I added "is-mobile" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
3. Finally, I was able to use this new custom shortcode, in the conditional block, by comparing it to a static value '1' for mobile and '0' for desktop.
( example screenshot attached )
regards,
Waqar
Thanks Waqar, your solution Worked perfectly!