How to hide post_meta on pages/posts in certain categories?

resolved (4 posts) (2 voices)

  1. margot620
    Member

    Hi all,

    I'd like to prevent the post_meta from showing in certain categories—I hope adding this code to my child theme's functions.php file might work, but if you know a better solution, I'd love to hear it:

    add_filter( 'mysite_post_meta', 'post_meta_filter' );
    function post_meta_filter($post_meta) {
    if (!is_page()) {
        $post_meta = '[56, 24, 53, 76]';
        return $post_meta;
    }}
    Posted 5 years ago #
  2. Elliott
    Support

    Hello margot620,

    Open up /wp-content/themes/[your_theme]/archive.php and add this on line 10,

    <?php if ( is_category( array( 9, 10, 11, 12 ) ) ) { ?>
    <style type = 'text/css'>.post_meta { display: none !important; }</style>
    <?php } ?>

    And then change the 9, 10, 11, 12, etc etc to whatever category ID's you wish to hide them on.

    Posted 5 years ago #
  3. margot620
    Member

    Thanks for the quick reply, Elliott, as always—I'm actually wanting to prevent the display when showing on a single post or a single page with the assigned category. Would I just use your solution in single.php?

    Posted 5 years ago #
  4. Elliott
    Support

    Yes you can use it in single.php also. If that does not work then add it to the loop template (loop.php) on line 13.

    Posted 5 years ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme