Can you guys help me with some examples so i can sort out the thumb posts from a specific category (EXAMPLE) to not be shown for not logged users, instead to be shown an image which tells them that they have to be logged in order to see that post.

Logged users can see all thumb posts. I tried to have this question short as possible, if need anything else i will do it. Thanks


You can hook a filter to the post_thumbnail_html and check if its a post in that category and if the user is not logged in ex:

add_filter( 'post_thumbnail_html', 'my_post_image_html_wpa92119', 10, 3 );

function my_post_image_html_wpa92119( $html, $post_id, $post_image_id ) {

    $category_to_exclude = "CHANGE_WITH_CATEGORY ID";

    //check if the post have that category nad if the user is not logged in
    if (has_category( $category_to_exclude ) && !is_user_logged_in())
        return '<a href="'.wp_login_url( get_permalink($post_id) ).'"><img src="'.$logIn_Img_path.'" alt="please log in"></a>';

    //if you got here then he is either logged in or its not the specified category
    return $html;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.