Have you ever needed to load a script to one or more of your Paid Memberships Pro pages? Use the code recipe to load scripts that you get from online platforms like Facebook Pixel and Google Analytics to your membership site.

Undraw Operating System

About the Code Recipe

There are a myriad of Apps, Web applications and Social Media platforms out there. Sometimes, in order to get specific data to and from your membership site, these platforms will require you to insert a script onto the pages of your website. For example, using a Facebook Pixel can help you set up cross-platform conversion tracking as well as cross-platform advertising by connecting your Facebook Business page and your membership site. Online services, like the Facebook Pixel, will usually require that you add a small snippet of code or ‘script’ to all pages of your website – including all Paid Memberships Pro pages.

Using the pmpro_hasMembershipLevel() function to create ‘members-only’ scripts.

In some cases, you may want to restrict certain scripts to be used or seen only by your members. To do this, you can use the pmpro_hasMembershipLevel() function to prevent non-users from accessing these scripts. We have an example of a ‘member-only’ script in action that you can read up on in our Members-Only Live Chat and Chatrooms using Arrowchat, iFlyChat, Wise Chat, Zopim blog post.

The Code Recipe

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

The code recipe above currently loads the script inside of the header section of your website. If you would like to rather add your script to the footer of your website be sure to replace wp_head with wp_footer instead.

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics
Was this article helpful?
YesNo