[resolved] Having Trouble Removing Comments from a Particular Category (3 posts)

  1. orvn
    Posted 3 years ago #


    I'm trying to hide comments from a few categories on my WordPress 3.4.1 site.

    Using PHP to accomplish this:

    <?php if ( in_category( array( "services", "team", "testimonials") ) {
    .commentsection {display: none;}
    } ?>

    But I get an unexpected '{' error.

    What am I doing wrong?

    Site is combined-effort.com

  2. patv
    Posted 3 years ago #

    You're missing a parenthese and closing php quotes (since you're not echoing your CSS rule, you're defining it inline :

    <?php if ( in_category( array( "services", "team", "testimonials") ) ) { ?>
    .commentsection {display: none;}
    <?php } ?>

    I'd also recommend that instead of setting a CSS rule based on if the page is in a certain category, place your check where the actual markup is being produced (such as in your comments.php or where the comment template file is being called in your template. Simply reverse the check (so !in_category(array()) ). This way you're not generating the markup needlessly and hiding it with CSS.

  3. orvn
    Posted 3 years ago #

    Thanks, I implemented that. I really appreciate the added suggestion too, I'm new to this, but I do try to keep things efficient.

Topic Closed

This topic has been closed to new replies.

About this Topic