How to Disable OptinMonster for WordPress Logged in Users

Want to avoid annoying active users with your campaigns? It’s easy with OptinMonster’s WordPress plugin!

In this article, you will learn how to automatically disable OptinMonster for logged-in users within WordPress.

Before You Start

Here are some things to know before you begin:

Disable for Logged In Users

This feature is great to use if you want to target a specific audience within WordPress.  Do you want to show your campaigns to guests and not bother your logged-in users?

When you are ready to hide certain campaigns from logged-in users, follow these steps:

  1. Log into the WordPress admin of your site and navigate to the OptinMonster > Campaigns screen.
  2. Hover over the campaign you would like to configure, and click Edit Output Settings below the title.
  3. In the Visibility & Status box on the right side of the screen, choose the audience you’d like to show the campaign to from the Who should see this campaign? dropdown field.
  4. Choose from the three options:
    • All Visitors and Logged-In Users
    • Visitors Only (not logged-in)
    • Logged-In Users Only
  5. When you are finished click Save Changes.

FAQs

How can I disable OptinMonster campaigns for visitors with specific user roles?

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.

function om_docs_hide_optin_for_user_roles( $campaigns ) {

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

	// Change these as necessary.
	$roles_to_check = array( 'administrator', 'subscriber' );

	// Get the current user.
	$user = wp_get_current_user();

	if ( ! empty( $user->roles ) && is_array( $user->roles ) ) {
		$has_role = array_intersect( $roles_to_check, $user->roles );
		if ( ! empty( $has_role ) ) {
			// Remove all campaigns for these particular roles.
			$campaigns = array();
		}
	}

	// Return the potentially modified campaigns.
	return $campaigns;
}
add_filter( 'optin_monster_api_final_output', 'om_docs_hide_optin_for_user_roles' );