%product_category%

#95413
  • Resolved Raoul
    Rank Math free

    Hi i added this to my functions.php

    /**
     * Filter to add custom variables
     */
    add_filter( 'rank_math/vars/replacements', function( $vars ) {
    	global $product;
    	if ( ! $product ) {
    		return $vars;
    	}
    
    	// Product Category
    	$vars['product_category'] = [
    		'name'    => 'Product\'s Category',
    		'desc'    => 'Current Product Category',
    		'example' => wp_get_post_terms( $_GET['post'], 'product_cat', array( 'fields' => 'names', 'number' => 1 ) )[0],
    	];
    
    	return $vars;
    });

    I added %product_cat% in Meta tag of product and it doesnt work

    I want to add at Titles & Metas the variable product category

    Product Example title: Buy %title% – %product_category% – %sitename% => ( Buy MEGA Shoes Blue – Men Shoes – Shoesshop.com)
    Product Meta example: Buy online %title%. See more products for %product_category% at sale => ( Buy online %title%. See more products for Men Shoes at sale)

    How to achieve this?

    Please add more variable, Yoast plugin had them and they are really useful

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m trying to do exactly the same thing, please add this variable %product_category%

    • This reply was modified 3 years, 6 months ago by Pull Noël.

    Hello,

    Thank you for getting in touch with us.

    To show WooCommerce product categories please use %customterm(product_cat)%

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘%product_category%’ is closed to new replies.