|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Show PMPro excerpts only for the post types you specify. |
| 4 | + * |
| 5 | + * title: Allow PMPro Excerpts for Specific Post Types |
| 6 | + * layout: snippet |
| 7 | + * collection: frontend-pages |
| 8 | + * category: content-protection |
| 9 | + * link: TBD |
| 10 | + * |
| 11 | + * You can add this recipe to your site by creating a custom plugin |
| 12 | + * or using the Code Snippets plugin available for free in the WordPress repository. |
| 13 | + * Read this companion article for step-by-step directions on either method: |
| 14 | + * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * To use this customization, be sure “Show Excerpts to Non-Members?” |
| 19 | + * is set to “Yes, show excerpts” in Memberships → Settings → Advanced Settings → Content Settings. |
| 20 | + * Only show PMPro excerpts for the selected post types. |
| 21 | + * Add any post type slugs to the $allowed_post_types array. |
| 22 | + */ |
| 23 | +function my_pmpro_allow_excerpts_for_specific_post_types( $showexcerpts ) { |
| 24 | + global $post; |
| 25 | + |
| 26 | + if ( empty( $post ) ) { |
| 27 | + return $showexcerpts; |
| 28 | + } |
| 29 | + |
| 30 | + // Edit this list to control which post types show excerpts. |
| 31 | + $allowed_post_types = array( |
| 32 | + 'movies', // Example of a custom post type slug called "movies". |
| 33 | + // 'post', |
| 34 | + // 'page', |
| 35 | + // 'custom_post_type_slug', // Add your custom post type slugs here. |
| 36 | + ); |
| 37 | + |
| 38 | + // Return true only for the post types listed above. |
| 39 | + return in_array( $post->post_type, $allowed_post_types, true ); |
| 40 | +} |
| 41 | +add_filter( 'option_pmpro_showexcerpts', 'my_pmpro_allow_excerpts_for_specific_post_types' ); |
0 commit comments