I'm not sure how to implement a change in my child theme's functions.php. In the woothemes documentation it says that "The functions.php in your child theme should be empty and not include anything from the parent themes functions.php."

I need to use this function to not display a product category, but I'm not sure how to do this in my child theme. Perhaps someone can refer me to instructions?

add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

function custom_pre_get_posts_query( $q ) {

if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() ) {

$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'hands-on' ), // Don't display products in the knives category on the shop page
'operator' => 'NOT IN'
  • 2
    Please indent your code properly, as it stands, it makes it hard to read and debug – Pieter Goosen Sep 3 '14 at 14:58

You should put your code in your child theme's functions.php file.

I believe that the documentation you reference is referring to the fresh state of the functions.php file and the fact that you don't need to copy a parent theme's functions into a child theme to use them.

| improve this answer | |
  • Thanks for your reply. So do I remove it from the parent to avoid it being overwritten? – RexTheRunt Sep 3 '14 at 16:33
  • Did you find it in the parent theme's functions.php file? – mrwweb Sep 3 '14 at 17:25
  • I did not have a child theme originally, so I added it to the main theme. Bad practice! – RexTheRunt Sep 4 '14 at 5:59
  • Yup. Get it out of there. If you put it in both, you'll get an error. – mrwweb Sep 4 '14 at 14:55

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.