0

I have a mobile version for my web-site and i used wp_is_mobile(). I will have a button on mobile devices which lets users to switch between the mobile and original versions. Is there a way to disable wp_is_mobile()? Or i can some how trick php to think that the mobile is not a mobile. Thank you for your time.

Note: I don't want to use display: none or other css. I need the content to not appear on mobile version in any ways.

2

wp_is_mobile() does not have any filters or ways to override. What you'll need to do is build a wrapper of your own around wp_is_mobile() and use that in your code where you've used wp_is_mobile().

Something like the following prototype could work for you. Ultimately a better option over the URL parameter might be to use a cookie value that you set/clear based on the user selected preference. See the PHP documentation on setcookie() for more on cookies.

function my_is_mobile() {
    static $is_mobile;

    if (isset($is_mobile)) return $is_mobile;

    if (isset($_REQUEST['mobile']) && $_REQUEST['mobile'] == "no")) {
        $is_mobile = false;
        return $is_mobile;
    }

    $is_mobile = wp_is_mobile();
    return $is_mobile;
}
  • thank you for your time, but i actually solved it already, still upvoting ). – Jurij Jazdanov Aug 7 '15 at 15:50
  • If you feel this is also a reasonable answer you could also mark it as answering your question. :) I'd certainly appreciate the recognition. – KenB Aug 7 '15 at 16:05
0

In most cases, you should be dealing with content switching at the CSS level. This can be accomplished in a variety of ways - the most popular of which is mobile-first responsive web design based on viewport width.

Say you had an element with a class of "mobile-hidden" - you could do something like this:

.mobile-hidden {
  display: none;
}

@media (min-width: 768px) {
  display: block;
}
0

Did it other way. I created a new theme for a mobile device and am using a plugin to switch between them.

0

You shouldn't use wp_is_mobile in frontend anytime. It's because of caching plugins, it won't work properly if you'd use someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.