Sjors Sjors - 1 month ago 11
PHP Question

Change code snippet to skip WooCommerce category pages

I use the code snippet below to add a title to the WordPress category pages, but unfortunately it also adds a second title to the WooCommerce product category pages. How should the code snippet be changed to skip the WooCommerce category pages? (something with is_product_category() ?)

// Prints a category's title and description (no markup added)
add_action( 'genesis_before_loop', 'output_category_info' );
function output_category_info() {

if ( is_category() || is_tag() || is_tax() ) {

echo '<h1 class="page-title">';
echo single_term_title();
echo '</h1>';

echo term_description();

}

}


With kind regards,

Sjors

Answer

You are right that you need to use is_product_category() conditional tag.

Here is the code :

// Prints a category's title and description (no markup added) 
add_action( 'genesis_before_loop', 'output_category_info' );
function output_category_info() {

    if ( is_product_category() ) {
        return;
    }

    if ( is_category() || is_tag() || is_tax() ) {

        echo '<h1 class="page-title">';
            echo single_term_title();
        echo '</h1>';

        echo term_description();

    }

}
Comments