Show non-members and search engines more of a restricted post before they hit the “Membership Required” message by extending how much of the post WordPress displays as an excerpt.
By default, WordPress shows only the first 55 words of a post as its auto-generated excerpt. For a protected post, that’s often all a non-member or a search engine crawler ever sees before being asked to join. This recipe extends the excerpt length for anyone who doesn’t have an active membership level, using the WordPress excerpt_length filter, so visitors and search engines get more context, more reason to join, and more content to index.
Do You Need This Recipe?
Use this recipe if you want non-members and search engines to see more than the default 55-word excerpt on your protected posts. If you already write excerpts manually for each post, or the default length works fine for your content and SEO goals, you don’t need it.
About the Code Recipe
This recipe uses the WordPress excerpt_length filter to change the excerpt length, but only for visitors without an active membership level. Members who already have access to a protected post see the full content as usual, since they won’t be shown an excerpt in the first place; everyone else gets a longer preview than WordPress’s default.
Understanding the excerpt_length Filter
excerpt_length is a core WordPress filter that runs whenever WordPress generates an automatic excerpt, meaning any post without a manually written excerpt. It receives the current excerpt length in words and expects a word count back. WordPress’s own default callback returns 55, which is why every auto-generated excerpt is capped at 55 words unless something else changes it.
This recipe’s callback checks pmpro_hasMembershipLevel() first. If the current visitor doesn’t have an active membership level, the callback returns 200 instead of 55, so non-members and search engine crawlers, which aren’t logged in either, get a longer excerpt. The callback is hooked at priority 20, so it runs after WordPress’s own default callback and overrides it.
The Code Recipe
Customize (line 25): To change how many words non-members see, update the 200 on the line that sets $length to whatever word count fits your site.
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.
Want to tweak this recipe? An AI coding assistant can help you adjust the code to fit your exact needs, or even add it to your site for you. Always test changes on a staging site first and keep a backup.
Rather have us handle it? With PMPro Max, you can submit a Do It For Me request, and our team will review it and, when possible, add or customize this recipe directly on your site.
No further customizations are needed for this code recipe.
Get Support From Our Team of Experts
Have a question about how to use this feature? Our Support Page outlines three ways to get support.
Our Max plans include hands-on help customizing your membership site and implementing new features. Upgrade to PMPro Max now »
