0

I'm new to Wordpress and am coming from the point and click world of Joomla! what was easy there now involves some solid php knowledge to replicate in Wordpress ;)

I'm try to conditionally remove post-meta and comments from 3 categories using functions.php

I'm using Woothemes Canvas and my own child theme.

I can remove post-meta globally by using an empty function:

function woo_post_meta() {}

This works fine but I only want it to work for 3 categories

I know I need to somehow use is_category butI'm not sure of the syntax, I tried

if ( is_category(4,5,6) ) {
    function woo_post_meta() {}
}

but that doesn't work, i'm not sure how to correctly write a function within a function.

Then how do i also remove comments from those categories? or should I make custom content type to do all this?

  • do you have any apply_filters() in the original woo_post_meta() function? – birgire May 27 '13 at 10:23
  • Hi Birgie, I'm not sure where to find the original woo_post_meta() function, I looked in theme-functions.php but it isn't mentioned in there. I will keep searching though, thanks – morktron May 27 '13 at 23:17
  • maybe under /wp-content/themes/your-theme-name/includes/theme-functions.php ? – birgire May 28 '13 at 9:36
  • Thanks Birgie, yes there is a theme-functions.php file in there but within that I'm not sure what I'm looking for. This is much more tricky than I though so for the time being I will try and use a custom theme file instead – morktron May 29 '13 at 3:08
1

Here are some ideas:

a) Instead of

is_category(4,5,6)

which checks if a category archive page is being displayed (see here), you can try

in_category(4,5,6)

or

in_category( array(4,5,6) )

that checks if the current post is assigned to any of the specified categories (see here).

b) You could also try

function woo_post_meta() {
    if ( in_category(4,5,6) ) {
        return "";
    }else{
     // the original woo_post_meta()  code here.
    }
}

c) If the original woo_post_meta() contains an output filter, than we could add a custom filter with the above category check.

d) If you write your own child theme, you could replace the template tag:

   woo_post_meta();

with

  if ( !in_category(4,5,6) ) {
       woo_post_meta();
  }
  • Excellent thanks Birgire, you have been an immense help!. I will play around with all of these solutions and bookmark this page as a resource for the future. Thanks again :) – morktron May 31 '13 at 1:17

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.