Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travislima/63061be20f114ff8d038d542499037ed to your computer and use it in GitHub Desktop.
Save travislima/63061be20f114ff8d038d542499037ed to your computer and use it in GitHub Desktop.
Do not return the post thumbnail (featured image) on restricted content when viewed by a non-member.
<?php
/**
* Do not return the post thumbnail (featured image) on restricted content when viewed by a non-member.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
*
*/
function hide_post_thumbnail_on_restricted_content( $html, $post_id, $post_image_id ) {
if ( function_exists( 'pmpro_has_membership_access' ) ) {
// Check if the user has access to the post.
$hasaccess = pmpro_has_membership_access( $post_id );
if ( empty( $hasaccess ) ) {
$html = '';
}
}
return $html;
}
add_filter( 'post_thumbnail_html', 'hide_post_thumbnail_on_restricted_content', 10, 3 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Hide a Post’s Featured Image From Non-Members" at Paid Memberships Pro here: https://www.paidmembershipspro.com/hide-a-blog-posts-featured-image-from-non-members/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment