How to Disable OptinMonster for Logged in Users

Want to avoid annoying active users with your campaigns? It’s easy with OptinMonster’s WordPress plugin! This guide will show you how to automatically hide your OptinMonster campaigns from visitors who are logged in to your WordPress website.

Important: Targeting users following this guide works only with websites that utilize WordPress.org’s Content Management System. It may be possible to target based on the logged-in status on other platforms using the display rules in the campaign Builder or using Google Tag Manager to control where the embed code is loaded on your site.
  1. OptinMonster Plugin
  2. Configure the Output Settings

Step 1 – OptinMonster Plugin

Log into the WordPress Admin and navigate to the OptinMonster > Optins screen. Here you’ll see a list of campaigns that have been synced to your site from OptinMonster. If you don’t yet see any campaigns available, or if the campaign you want to configure isn’t shown, select the Refresh Optins button to sync the latest campaigns.

Next, select the Edit Output Settings link below the title of the specific optin you wish to configure:

Select the Edit Output Settings link to configure where your campaign should appear on your site.

Step 2 – Configure the Output Settings

This will open the Output Settings screen where we’ll configure who can see the campaign. Look to the Who should see this optin? setting, which has the following options available:

  • Show optin to all visitors and users
  • Show optin to only visitors (not logged-in)
  • Show optin to only users (logged-in)

After specifying your Output Settings, save the changes and visit your site to see the new setting in effect.

Configure the output settings to output the campaign embed code only for specific user roles.

That’s it, save the settings and the campaign embed code will not be added to your site only if the user’s logged-in status meets the settings defined in the Output Settings!

If you want to disable OptinMonster for a specific user role in your membership site, then simply paste the following code in your theme’s functions.php file.

add_filter( 'optinmonster_output', 'tgm_om_hide_optin_for_user_roles' );
function tgm_om_hide_optin_for_user_roles( $optins ) {

    // Do nothing if no user is logged in.
    if ( ! is_user_logged_in() ) {
        return array();
    }

    // Get the current user.
    $roles = array( 'administrator', 'subscriber' ); // Change these as necessary.
    $user  = wp_get_current_user();
    if ( ! empty( $user->roles ) && is_array( $user->roles ) ) {
        if ( in_array( $roles ), $user->roles ) {
            $campaigns = array(); // Remove all campaigns for these particular roles.
        }
    }

    // Return the potentially modified campaigns.
    return $campaigns;

}