Browser specific popup

Hello, I just installed PopUp Pro. I need to only show a popup when a visitor is using MS Internet Explorer or MS Edge. Can you tell me how I can do that?

  • Pawel
    • Staff

    Hello Waylon!

    Hope you are having a great day!

    I’ve got a solution for you. There’s no option to detect browsers in Popup Pro itself, but you can workaround this.

    First, please add the following snippet of code to the end of your theme’s functions.php file (can be done via Appearance->Editor after selecting functions.php in the right side panel):

    function custom_body_classes($classes) {
    $browsers = ['is_iphone', 'is_chrome', 'is_safari', 'is_NS4', 'is_opera', 'is_macIE', 'is_winIE', 'is_gecko', 'is_lynx', 'is_IE', 'is_edge'];
    $classes[] = join(' ', array_filter($browsers, function ($browser) {
    return $GLOBALS[$browser];
    }));
    return $classes;
    }

    add_filter('body_class', 'custom_body_classes');

    This will add classes like is_chrome, is_IE, is_edge for each browser.

    Then, in your popup settings, you enable the setting in Behaviour->Appear after user scrolled until CSS selector (see screenshot) and fill in with something like this:

    body.is_edge, body.is_IE, body.is_macIE, body.is_winIE

    This workaround has only one slight drawback: the visitor has to scroll the page at least just a bit for the popup to appear. But that’s the best and cleanest solution to your case.

    kind regards,

    Pawel

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.