Category Archive Descriptions Automatic coverage

#726881
  • Resolved Li frank
    Rank Math free

    Hello, I’m trying to automatically apply the Category Archive Descriptions I set up in rankmath to all my product categories and product title pages.
    But the settings here seem to be enabled only when there is no setting description on the page.
    How can I make the settings here apply regardless of whether I set a separate description? In other words, this will be set as the meta description of the product category and tag page, instead of using the description I set in woocommerce.
    Is it possible to use the following code:
    /**
    * Use the Description from Global Setting for Categories, overriding individual category meta
    */
    add_action( ‘rank_math/frontend/description’, function( $description ) {
    if ( is_category() ) {
    $term_id = get_queried_object_id();
    $desc = RankMath\Helper::get_settings( “titles.pt_category_description” );

    if ( $desc ) {
    return RankMath\Helper::replace_vars( $desc, get_term( $term_id ) );
    }
    }

    return $description;
    });

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

    I apologize for the inconvenience you’re facing with the Category Archive Descriptions in Rank Math. The setting you’re referring to will indeed only be applied when there is no individual description set for a page.

    To override individual category meta descriptions and use the global setting for categories, you can use the provided code snippet. This code will allow you to set the global description for categories and override individual category meta descriptions.

    However, please note that this code is specifically for categories and not for product category and tag pages. If you want to apply this to product category and tag pages, you may need to modify the code accordingly.

    If you have any further questions or need assistance with modifying the code, please feel free to reach out to our dedicated support team here.

    We appreciate your understanding and patience as we work through this together.

    Sources:
    How to Set Product Meta Description Using Rank Math » Rank Math
    Rank Math SEO Filters and Hooks for Developers – Rank Math
    Rank Math ‘Titles and Meta’ Options and Settings

    Hello,

    Thank you for contacting Rank Math support.

    You can use the following filter to set the product category and other taxonomies’ meta description from the Titles & Meta settings instead of the one set in the snippet editor:

    add_action( 'rank_math/frontend/description', function( $generated ) {
    	$term = get_queried_object();
        if(is_tax()) {
    		$desc = RankMath\Helper::get_settings( "titles.tax_{$term->taxonomy}_description" );
    		$desc = RankMath\Helper::replace_vars( $desc, $tax );
    		return empty( $desc ) ? $generated : $desc;
    	}
    		return $generated;
    });

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

    Thank you for your help!
    In addition, I am also using some code to try to cover the meta descriptions of all products, let them uniformly replace the default settings, and use the template I set in rank math:
    add_action( ‘rank_math/frontend/description’, function( $description ) {
    if ( ! is_product() ) {
    return $description;
    }

    global $post;
    // Get the product description template from Rank Math’s global settings.
    $desc_template = RankMath\Helper::get_settings( “titles.pt_{$post->post_type}_description” );

    // If a template is set, replace variables and return it.
    if ( $desc_template ) {
    return RankMath\Helper::replace_vars( $desc_template, $post );
    }

    // If no template is set, return the original description.
    return $description;
    });

    But this code is not working correctly. Do you know what I should do to automatically use the unified template I set in rank math? My product description template is as follows:
    Get %title% From Greta At Unbeatable Price With No MOQ, Best Wholesale and Dropshipping Lingerie Supplier.

    Finally, how can you and I make the code you provide me work? I placed it in the function file of the theme, but the product category description still seems not to be replaced. My product category description template is as follows:
    Wholesale %title% From Greta With Free Shopify Sync And No MOQ, Best Wholesale and Dropshipping Lingerie Supplier.

    Thank you for your help!

    Hello,

    You can use the following filter to force the product description from Titles & Meta settings:

    add_action( 'rank_math/frontend/description', function( $generated ) {
    	if ( ! is_product() ) {
    		return $generated;
    	}
    
    	global $post;
    	$desc = RankMath\Helper::get_settings( "titles.pt_product_description" );
    	$desc = RankMath\Helper::replace_vars( $desc, $post );
    	return empty( $desc ) ? $generated : $desc;
    });

    Please note that the filters will add the correct description in the front end, but you will still see the short description in the snippet editor of the meta box.

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

The ticket ‘Category Archive Descriptions Automatic coverage’ is closed to new replies.