• Resolved korvak

    (@korvak)


    Is there a way to add a custom prefix to the Woocommerce category page titles only?

    For example: Category title “ABC” would become “Buy ABC”

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    We have little demand for this feature: https://github.com/sybrew/the-seo-framework/issues/140.

    Still, you can add it programmatically. Let me know if this interests you, and I can write you a filter.

    Thread Starter korvak

    (@korvak)

    Sure! What’s the filter to use?

    Thread Starter korvak

    (@korvak)

    Any update on this?

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi!

    Sorry about that! I missed your message. Here you go:

    add_filter( 'the_seo_framework_use_archive_prefix', function( $use, $term ) {
    
    	if ( 'product_cat' === ( $term->taxonomy ?? '' ) )
    		$use = false;
    
    	return $use;
    }, 10, 2 );
    
    add_filter( 'the_seo_framework_title_from_generation', function( $title, $args ) {
    
    	$is_product_category = false;
    
    	if ( null === $args ) {
    		$is_product_category = function_exists( 'is_product_category' ) && is_product_category();
    	} else {
    		if ( $args['taxonomy'] ) {
    			$is_product_category = 'product_cat' === ( $args['taxonomy'] ?? '' );
    		}
    	}
    
    	if ( $is_product_category )
    		$title = "Buy $title";
    
    	return $title;
    }, 10, 2 );

    The first filter removes the Category: prefix (if any), and the second adds Buy in front of the title product category title.

    (Where to place filters?)

    This may not always be reflected correctly in the title placeholders of the SEO Meta settings. This is only a visual glitch in the admin area because TSF tries to build a new title on the fly as you edit the category name.

    Cheers ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom prefix for category pages?’ is closed to new replies.