1

we have a website running on WPMU, and the main site is using Woo-commerce and the sub sites doesn't use that. I use conditional statement in my meta title with following code:

<title>
<?php if( is_product_category( 'cds' ) ) { ?>
CD
<?php } elseif ( is_product_category( 'dvds' ) ) {?>
DVD
<?php } else {?>
<?php wp_title( '|', true, 'right' ); ?>
<?php } ?>

but the thing is the sub sites, can not read this code, because the Woocommerce functions are undefined in those. I almost sure that there is no way to identify a Woocommerce product page by WP core conditional tags, Do you guys have any idea how can i identify them?

  • Wrap your code in is_main_site(), or better yet, function_exists( 'is_product_category' ) – TheDeadMedic May 24 '14 at 19:07
  • @TheDeadMedic Works fine, Post it as an answer and i can mark it then. – user3067592 May 27 '14 at 15:51
1

You can rewrite you code as

        <title>
        <?php if (!function_exists( 'is_product_category' )) {
        if( is_product_category( 'cds' ) ) { ?>
        CD
        <?php } elseif ( is_product_category( 'dvds' ) ) {?>
        DVD
        <?php }
        }else { wp_title( '|', true, 'right' ); } ?>

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.