Lesson notes
How it works
Showing content by plan without a gated content group
data-ms-content with a content ID needs a gated content group for every plan. MemberScript 188 skips that. You tag elements with a plan ID and the script decides who keeps them. Memberstack's own docs point to this script for exactly that case.
Paste the script into the page's custom code, or into your site-wide custom code if you'll use it on many pages. Then add the custom attribute data-ms-code to each element, with the plan ID as the value, for example data-ms-code="PLAN_ID". Two elements with two different plan IDs gives you one element for each plan.
- Add MemberScript 188 to the page or to your site's custom code.
- Select the element for your first plan and add
data-ms-codewith that plan's ID. - Select the element for your second plan and add
data-ms-codewith its plan ID. - Publish, then log in as a member on each plan to check which element stays.
What the script does on page load
When the page loads, the script waits for Memberstack, then gets the current member. If nobody is logged in, or the member has no plan, it removes every element that has data-ms-code. If the member has a plan, it reads the plan ID and price ID of their first plan connection and keeps only elements whose value matches one of them. Every other tagged element is removed from the page, not just hidden, so you can use either a plan ID or a price ID as the value.
This still runs in the browser, so treat it as a way to tidy the page for each plan, not as protection for anything valuable.
How to stop content flashing
Until the script runs, every tagged element is on the page, so visitors can see both items for a moment before one disappears. MemberScript 23 covers that gap with a skeleton loader. Add the script, then put the attribute ms-code-skeleton on the container that holds your plan items. The value is how long the loader shows, in milliseconds. The loader doesn't wait for MemberScript 188, it just covers the container for that time, so pick a value long enough for the plan check to finish. If the value isn't a number, it shows for 2000 milliseconds. The script page has a light and a dark version.