Structure data based on product categories (or tags)

#92791
  • Resolved Hoang Thai
    Rank Math free

    Hello, I just want to ask if it is possible to create different SEO Titles & Meta for products in specific category (or tags). For example: All products in category A will have the same Product Title and Product Description, but it will different from ones in category B. Thank you.

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

    Thank you for getting in touch with us.

    I am sorry but we currently do not have such a feature in place.

    You can however use our provided filters to modify meta and assign them according to product categories. Here are the links to modify the title and the description.

    You may have to hire a developer to assist you in customizing this then add it to your functions.php

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

    Hello

    To add further to what my colleagues said, you can change the title & Description based on the Category:
    https://rankmath.com/kb/filters-hooks-api-developer/#change-the-title
    https://rankmath.com/kb/filters-hooks-api-developer/#change-meta-description

    Hope that helps. Thank you.

    Hello,
    Thank you for your support, I managed to write some conditions in PHP and put it in your provided custom filters.

    function custom_meta_title_override() {
    if (is_product()) {
    	global $product;
    	$id = $product->get_id();
    	$name = $product->get_title();
    	if (has_term( 'special-shaped', 'product_cat', $id)) {
        	return 'Buy ' . $name . ' Special Shaped Diamond Painting Kit at 30% Off | PNC'; }
    	else if (has_term( 'diamond-painting-kits', 'product_cat', $id)) {
        	return 'Buy ' . $name . ' Diamond Painting Kit at 30% Off | PNC'; }
    	else {
    		return 'Buy ' . $name . ' at 30% Off | PNC'; 
    		}
      } 
    } 
    add_filter( 'rank_math/frontend/title','custom_meta_title_override');

    However, I’m afraid that this function will hurt my page performance if I need to customize more categories or specific products based on ID, with these if/else conditions. So I want to ask if there are any conditional functions on Rank Math to check if the products already have custom meta in the product admin (in this image http://prnt.sc/v2qeid) so the filters won’t run on specific products (which meta title and description already applied).

    Hello,

    You can check if the post is already assigned meta description as follows:

    
    global $post;
    $desc = RankMath\Post::get_meta( ‘description’, $post->ID );
    
    if(!desc){
     //use defined description
    }
    

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

    Hello, thank you for prodiving those lines of code.
    However, it seems that the custom meta title and description on each product isn’t working. I defined these custom title and description on 1 of my product in the screenshot: https://prnt.sc/v49jod
    But it is using this global meta settings in this screenshot instead: https://prnt.sc/v49kwv
    Also, your provided code will check the global custom title, does that mean I need to leave the product global title and description empty in order to make my custom filter works?

    Hello,

    Could you please share the final code you are currently working with?

    We can also look into this from your site. Please edit the first post on this ticket and include your WordPress logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,
    This is the codes I was working with (I reverted back to the previous one I sent you because these codes didn’t work).

    function custom_meta_title_override() {
        global $post;
        $desc = RankMath\ Post::get_meta(‘description’, $post - > ID);
        if (!desc) {
            if (is_product()) {
                global $product;
                $id = $product - > get_id();
                $name = $product - > get_title();
                if ($id == 12719) {
                    return 'Buy '.$name.
                    ' Diamond Painting at 30% Off | Pretty Neat Creative';
                } else if (has_term('special-shaped', 'product_cat', $id)) {
                    return 'Buy '.$name.
                    ' Special Shaped Diamond Painting Kit at 30% Off | Pretty Neat Creative';
                } else if (has_term('diamond-painting-kits', 'product_cat', $id)) {
                    return 'Buy '.$name.
                    ' Diamond Painting Kit at 30% Off | Pretty Neat Creative';
                } else {
                    return 'Buy '.$name.
                    ' at 30% Off | Pretty Neat Creative';
                }
            }
        }
    }
    add_filter('rank_math/frontend/title', 'custom_meta_title_override');
    Alberto
    Rank Math business

    Hello,

    I have sent this thread to the devs so they might be able to help you.

    Looking forward to help you.

    Hello, any updates on my issues?

    Hello,

    Please update to the latest version and let us know if the issue persists.

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

The ticket ‘Structure data based on product categories (or tags)’ is closed to new replies.