How do I add a product attribute in SEO title?

#586350
  • Resolved Anonymous
    Rank Math free

    Hi,

    I want to add a product attribute (I use Woocommerce) in SEO title?
    I have tried with %customterm(taxonomy-name)% but it doesn’t work…

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    Thank you for reaching out to us and bringing your concern to our attention.

    At the moment, our plugin is limited to adding the product attribute as we only have selected attributes such as the %wc_brand%.

    If you have custom attributes you can try creating a custom variable that you can use for your meta title:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'rankmath_product_attribute', [
    	   'name'        => esc_html__( 'Author name', 'rank-math' ),
    	   'description' => esc_html__( 'Author description', 'rank-math' ),
    	   'variable'    => 'rankmath_product_attribute', /* the actual variable: %rankmath_product_attribute% */
    	   'example'     => rankmath_product_attribute_call_back(),
    	   ],
    	   'rankmath_product_attribute_call_back'
       );
    });
    function rankmath_product_attribute_call_back(){
    	$product_id = get_the_ID();
    	$custom_attribute_value = get_post_meta( $product_id, 'ATTRIBUTE_KEY', true );
    
    	return $custom_attribute_value;
    }

    After applying the code, you can use the variable %rankmath_product_attribute% in your meta titles.

    You may refer to this guide on how to add the code to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

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

    Anonymous
    Rank Math free

    Thanks!
    do I have to add the custom attribute in the snippet? Or do I have to use the variable %rankmath_product_attribute(my-attribute)% in the meta title?

    Hello,

    Thank you for getting back to us.

    Once you have created a custom variable, you can use it anywhere variables are accepted, including both the snippets section and in your meta title.

    Regards,

    Anonymous
    Rank Math free

    So, in order to do this, if I want to use the custom attribute ‘writer’, do I have to replace ‘rankmath_product_attribute’ with ‘writer’ in the snippet?

    Hello,

    Sorry for the confusion. You don’t have to create a custom variable. You can use the %customterm(term-name)% variable to add the value of the product attributes in the fields of our plugin.

    For the writer attribute, you can use %customterm(pa_writer)%. Please note that the value will be applied in the front end and the preview in our meta box will show Custom Term Value instead of the actual value.

    Hope that helps. Let us know if you need any other assistance.

    Anonymous
    Rank Math free

    Thanks! Now it works!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘How do I add a product attribute in SEO title?’ is closed to new replies.