By default, Paid Memberships Pro hides some of our required frontend pages from your site’s search results, like your Membership Account and Membership Confirmation page. Hiding these pages streamlines your site’s search results and helps people find the most meaningful content when using the search feature.

While most sites prefer to keep this filter in place, there are some sites that want to add the PMPro frontend pages back to search.

This blog post includes a code snippet that reverses the default setting, adding your site’s PMPro frontend pages back to the search results. 

Banner Image for Show the Paid Memberships Pro Required Pages in Site Search

Understanding the Role of pre_get_posts

Before sharing the code recipe, let’s break down the role of the pre_get_posts action hook in WordPress. This hook allows developers to set custom query parameters before WordPress retrieves posts. It’s used to modify and customize all types of queries throughout your WordPress site, not just for searches.

In the context of PMPro, we use this hook to exclude some frontend pages that are really only useful in the context of a member managing their account and billing information.

What pages are excluded? If you navigate to Memberships > Settings > Pages in the WordPress admin, you’ll see a list of all the default page settings for your site. All of these assigned pages will not appear in search results.

Screenshot of the Paid Memberships Pro page settings in the WordPress admin

If you want to include these pages in search results, you’ll need to put them back using the code recipe in this article.

Impact on Your Site

The decision to include PMPro pages in your site search results should align with your overall website strategy and user experience goals. Some sites might find that adding these pages back to search results makes them more easily accessible for logged-in members.

Others will opt to keep the default filter in place. Going this route, non-members will not have search results for terms like “membership” and “member” cluttered with pages that they can’t access. Non-members get redirected away from these pages anyway, as they are account-related pages only members need to use.

Now that you understand the basics of the pre_get_posts hook, you can safely use the code recipe below.

About the Code Recipe

The provided code recipe is designed to include all PMPro frontend pages in your WordPress site’s search results. By default, PMPro excludes its pages from site search results to keep membership account-related content separate. The code snippet below removes this filter, making PMPro pages searchable and visible in the site search results.

Screenshot of code recipe in use - membership account page shown in search results

The Code Recipe (PHP)

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.

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