How can I make use of WP Mobile Detect conditions from within a plugin?

I recently downloaded the WP Mobile Detect plugin and integrated it to my theme (the original mobile detect library I include from the theme folder and the matching WP-functions I pasted directly into functions.php).

Now I have one Social Share Plug-In I only want to appear when the site gets requested by desktop devices. So I tried modifying the core files of that plugin, wrapping the output function inside a condition of WP Mobile Detect, like:

Read More
if ( ! wpmd_is_phone() ) { // output my share buttons }

Unfortunately, this will return a Call to undefined function. How can I fix this?

Related posts

1 comment

  1. You either have to include/require the WPMD file that includes the function(s) you are using, or just use the globally defined $detect object, like so:

    global $detect;
    if (! $detect->isMobile() || $detect->isTablet()) {
        // output your share buttons
    }
    

    // EDIT
    The above conditional is the equivalent of your ! wpmd_is_phone() conditional. However, if you want to restrict this to desktop devices only, you should use the following:

    global $detect;
    if (! ($detect->isMobile() || $detect->isTablet())) {
        // output your share buttons
    }
    

Comments are closed.