In this post we'll show you how to display or hide WordPress widgets conditionally based on a member's existing ActiveCampaign tags or current membership level.
To do this, the first step is to install and activate a free WordPress plugin called "Widget Logic" to your site.
Once Widget Logic is installed, here's an overview of how to display widgets conditionally based on a members tags, existing membership levels, or based on being logged in or not.
How to display a Widget to members with a specific membership level: memb_hasMembership
memb_hasMembership() allows you to show or hide a Widget by membership level.
Any widget that uses the function memb_hasMembership() will be hidden from logged out visitors.
To use this, we'll need to find the exact name of the membership level that you want to display the widget for.
In the admin area of your WordPress site, navigate to 'Memberium > Memberships' and find the name of the membership level you're looking for and copy it.
Let's say we want to display a Widget only to members with the 'Gold' membership level.
You'd use the following example function in the "Visibility" box (be sure to exactly match the name of your membership level, names are not case sensitive):
memb_hasMembership( "Gold" )
To display a Widget to members who are not 'Gold' members, you'd use the following function in the "Visibility" field with an exclamation point(!) in front of the function to reverse the visibility logic:
!memb_hasMembership( "Gold" )
A few quick examples of how you could use this on your site are:
Displaying a 'custom menu' widget for a specific membership levels content, displaying a widget with an ad or offer for free members to upgrade to a paid membership, displaying a one click upsell offer for existing paid customers to upgrade their membership or purchase an additional product.
How to display a Widget to members who have ANY of the following ActiveCampaign tags: memb_hasAnyTags
The function memb_hasAnyTags allows you to display widgets by WordPress tag. To display a Widget by ActiveCampaign tags you'll need to find the “tag id” first.
To find the ID for a tag that's not a membership level (to display a Widget based on membership level, you should only use memb_hasMembership and not memb_hasAnyTags), you can find the tag ID by acting like you're creating a new post in WordPress and typing in the name of the tag in the "Require tag IDs" field of the Memberium Content Protection Box:
To display a Widget to a member who has a specific ActiveCampaign tag, for example let's say the tag id of '130', all you need to do is paste the following into the "Widget Logic" box (be sure to include your own tag ID in place of '130'):
memb_hasAnyTags( "130" )
To hide the Widget from anyone who has this tag, and display it to anyone without it, you just need to add an exclamation mark in front of the function:
!memb_hasAnyTags( "130" )
If you want to hide or show a Widget from anyone who has ANY of the following ActiveCampaign tags you just add a comma between the tag id's.
This will display a Widget to members with any of the following ActiveCampaign tags:
memb_hasAnyTags( "130,128" )
This will hide a Widget from any member with any of the following ActiveCampaign tags:
!memb_hasAnyTags( "130,128" )
A few quick examples of how you could use this on your site is:
Display a widget with a button/ad that leads to a sales offer, present a one click up-sell offer to existing customers or display a failed payment notice for customers with past failed payments or expired credit cards.
You can also display 'custom menus' as widgets that you can control conditionally using the functions covered in this post.
How to display a Widget to members who have ALL of the following ActiveCampaign tags: memb_hasAllTags
In certain situations you'll want to display or hide a Widget from members who have multiple ActiveCampaign tags.
In this example let's say we only want to display a Widget with a sales offer to someone who has completed our premium training course and has another tag.
To display a Widget for a member who has ALL of the ActiveCampaign tags specified you would use the following function in the "Widget Logic" box (be sure to add your own tag id's in place of the example):
memb_hasAllTags( "130,128" )
To hide a Widget from a member who has ALL of the following ActiveCampaign tags you would use the following in the "Widget Logic" box:
!memb_hasAllTags( "130,128" )
How to display a Widget based on a user being logged in or out: memb_is_loggedin
To display a Widget only to members who are logged in, you'd use the following example in the "Widget Logic" box:
This Widget will be hidden completely from any logged in user and will only display to visitors who are logged out:
An example of how you could potentially use memb_is_loggedin() is to display an opt in offer through a widget to logged out visitors only and display a different widget to users who have already opted in to move them through your sales funnel.
Combining Multiple Functions
You can combine multiple functions or use any other PHP / WordPress functions together to create more advanced visibility conditions for Widgets.
In this example let's say we want to display a Widget only for "Gold" Members who have the ActiveCampaign tag id of "130":
memb_hasmembership( "gold" ) && memb_hasanytag( "130" )
To combine two or more functions together, you just add two ampersands between them like so: &&
If we wanted to reverse the visibility logic, you'd use the following function:
!memb_hasmembership( "gold" ) && !memb_hasanytag( "130" )
In addition to the above conditional tags you can also use any PHP functions to build complex display conditions for widgets if you're familiar with PHP and are an advanced WordPress user.
You can also use WordPress' default conditional tags to display widgets conditionally based on specific pages, posts, categories and other options.
Displaying widgets conditionally can be used in a number of different ways to help deliver a more personalized experience for your members.
Here's a few other real life examples of how you could use this to improve your membership site:
- Showing opt ins to logged out users only.
- Displaying "custom menu's" in widgets conditionally.
- Hiding sales page offers from customers who have purchased them already.
- Display sales offers in your sidebar or footer widgets.
- Display a 'Update your Payment Info' message for failed payments.
- Display a 'Pay Past Due Invoices' notice failed payments.
- Showing or hiding certain widgets, opt in's or targeted offers based on a user's existing ActiveCampaign tags.
- Displaying an up-sell offer in your sidebar.