Custom Title & Meta Template for Product Categories

  • Hi RankMath team,

    I’ve just tried and loved RankMath so far! Great plugin!

    I want to ask one question about title & meta template for product categories on WooCommerce.

    Let’s say I have 2 categories: Tools, Accessories. I want to create 2 different title/meta templates for all products belong to them.

    – Tools: “Buy %product_title% AAA Tools 20% OFF | %brand%”
    – Accessories: “Buy %product_title% BBB Accessories 30% OFF | %brand%”

    How can I can do that with RankMath?

    Thanks,
    Hieu.

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

    Thank you for contacting Rank Math today.

    Assuming you are on Accessories category, you can set your title settings as shown in this screenshot: https://i.rankmath.com/Dd6F2R. This will use the current post/page seo title, and if you have perfect brand for woocommerce plugin, wc_brand will use the set brand.

    The other option would be to add custom variables to Rank math drop-down in titles & meta using the filter here: https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-variables

    Looking forward to helping you. Thank you.

    ​​​​​​

    thanks for your answer hmm, maybe my explanation was not accurate.

    Here is what I want to customize: apply custom title/meta to all products in 1 category.

    Let says in category Accessories, all products will have SEO titles like “Buy %product_title% Accessories at 30% OFF”
    – Product A: “Buy A Accessories at 30% OFF”
    – Product B: “Buy B Accessories at 30% OFF”
    – Product C: “Buy C Accessories at 30% OFF”

    And all products in category Tool have different template: “Buy %product_title% Tools NOW”
    – Product X: “Buy X Tools NOW”
    – Product Y: “Buy Y Tools NOW”

    Hope it’s clearer.

    How can I do it in bulk?

    Thanks,
    Hieu.

    Hello,

    Rank Math does not have that feature (yet) but it sounds really interesting. Maybe you could achieve it by using the following filter and checking on which category you are (but you will need to know something about coding to modify this according to your needs or hire a dev to do it for you):

    /**
     * Allow changing the meta description sentence from within the theme.
     *
     * @param string $description The description sentence.
     */
    add_filter( 'rank_math/frontend/description', function( $description ) {
    	return $description;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hello, SEO friends 🙂
    Help to make an example correctly:

    add_filter( 'rank_math/frontend/title', function( $title ) {
        if ( in_category( 'category-name or ID' ) ) { // how?
        	$title = $title. 'my text';
        }
        if ( in_category( 'category-name-2 or ID-2' ) ) { // how?
        	$title = $title. 'my text-2';
        }
      return $title;
    });

    If the title is generated for the post, display the code, if the title is written manually, display the manual title.

    Простите меня за Google Translate 😀

    Hello,

    I am not sure about the changes you are trying to do in the code. Do you mean you want to check if a SEO Title is already set for the posts in the category and if they are not set, use the custom one you enter in the code? Or what do you mean?

    Looking forward to help you.

    I want to do what the author of the problem described.
    For posts from different categories, use a custom title and description template. BUT! If the title and description of the post is used manually from the admin panel, then do not apply the custom template from the code.

    Do you support anyone who speaks Russian? 🙂

    Hello,

    add_filter( 'rank_math/frontend/title', function( $title ) {
       global $post;
     $var = RankMath\Post::get_meta( 'title', $post->ID );
    
     if ( ! $var && get_category==('yourcategory') ) {
      $title = $title . 'your custom text';
    }
      return $title;
    });
    

    Hope that helps. If you have any further question(s), please let us know. Thank you.

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

You must be logged in to reply to this ticket.