Add brand (taxonomy) to product meta tag

#179185
  • Resolved Roeland Vreugdenhil
    Rank Math free

    Hi,

    I’d like to add the brand name in the product meta title. How do i accomplish this (it’s a product attribute + taxonomy). I already created a shortcode for the product brand if thats helpful.

    Thanks!

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math support today.

    Here is a filter function that will help you create a custom variable for your meta title:

    /**
    * Action: 'rank_math/vars/register_extra_replacements' – Allows adding extra variables.
    */
    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    		'my_product_brand', //variable to add
    		[
    			'name' => esc_html__( 'Product Brand', 'rank-math' ), //variable name
    			'description' => esc_html__( 'Custom variable description.', 'rank-math' ), //variable description
    			'variable' => 'my_product_brand', //variable itself
    			'example' => get_my_product_brand_info(),
    		],
    		'get_my_product_brand_info'
    	);
    });
    	
    /* define you callback function, how and where to get the variable data */
    function get_my_product_brand_info(){
    	return 'my product brand';
    }

    Insert this code in your theme’s functions.php file and you should be able to use it by inserting this custom variable to your meta fields: %my_product_brand%

    Let me know if this code works on your end.

    We are looking forward to helping you.

    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 1 replies (of 1 total)

The ticket ‘Add brand (taxonomy) to product meta tag’ is closed to new replies.