Change / Alter Product Category Link with Page Link


I’m using this snippet to alter a specific Category link with Page Link and its working well :

function wpa_alter_cat_links( $termlink, $term, $taxonomy ) {
    if( 'category' == $taxonomy && in_array( $term->slug, [ 'category-1', 'category-2' ] ) ) {
        return str_replace( '/blog/category', '', $termlink );
    return $termlink;
add_filter( 'term_link', 'wpa_alter_cat_links', 10, 3 );

The above code comes from this other WPSE Question: Force WordPress to Show Pages Instead of Category. Now I want to do the same thing for a product-category. For example:

Change/Alter /shop/category-name/ with simply /category-name/

How can I do this?

Milad Jafari 4 months 0 Answers 7 views 0

Leave an answer