• Hi,

    I have an archive page for a specific category and I would like to remove the link on the featured image (I wish to keep the featured image). I came across this code which I think removes the link from ALL featured images:

    <?php if ( has_post_thumbnail()) : ?>
     //remove opening a tag
       <?php the_post_thumbnail(); ?>
    //remove closing a tag
     <?php endif; ?>

    I think I just need to adapt this so that the if statement checks which category before removing it. My category ID is 4167, so do I insert something like this in my functions file?

    if ( in_category( '4167' ) ) {
    
    if ( has_post_thumbnail()) : ?>
     //remove opening a tag
       <?php the_post_thumbnail(); ?>
    //remove closing a tag
     <?php endif; ?>
    
    }

    I am not great at php so I am unsure if this is correct.

    Any pointers appreciated, thanks.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Yes, the code looks quite plausible. You can do it that way, I think. Remember to leave the normal path in the else branch after the condition, so:

    if ( in_category( '4167' ) ) {
    if ( has_post_thumbnail()) : ?>
    //remove opening a tag
    <?php the_post_thumbnail(); ?>
    //remove closing a tag
    }
    else {
    // use the original code here
    }

    I see that you are already using a child theme. Of course, you should only make this change in this theme.

    Thread Starter demonboy

    (@demonboy)

    Thank you for the reply. It’s ok to stack if statements like I have then?

    Sure, it’s entirely up to you. Just make sure that the content works properly.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Remove link from featured image in a specific category’ is closed to new replies.