Meta description template instead of short description

#957589
  • Resolved Leon Mirčić
    Rank Math free

    Hi,

    after adding short descriptions for our products (WooCommerce) products started using short descriptions instead of description template for meta description.

    As per this response form your support, when short description s added for a product, the template will be ignored.

    https://prnt.sc/TR1XdeTXyRC8
    Support answer

    Is there a way or code we can add to set it up so that the template isn’t ignored, except when the meta description field has content?

    Using: RankMath PRO

    Thank you in advance!

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

    We apologize for the issue you are facing with the meta description for your WooCommerce products. Thank you for raising this concern.

    As per the information you’ve referenced, when a short description is added to a product, it indeed takes precedence over the meta description template set in Rank Math. Unfortunately, there isn’t a built-in option to change this behavior directly within the plugin settings.

    However, you can achieve the desired functionality by using a custom code snippet. You can add the following code to your theme’s functions.php file:

    add_filter('rank_math/frontend/description', function($description, $post) {
        if (empty($description) && !empty($post->post_excerpt)) {
            return $post->post_excerpt; // Use short description if meta description is empty
        }
        return $description; // Otherwise, use the existing meta description
    }, 10, 2);

    This code checks if the meta description is empty and uses the short description only in that case. If you have set a meta description, it will use that instead.

    Please ensure to back up your site before making any changes to the code. If you’re not comfortable adding code yourself, we recommend consulting with a developer.

    If you have any further questions or need assistance, feel free to reply to this ticket, and a human agent from the Rank Math Support team will assist you further!

    Sources:
    Google Shows A Different Meta Title/Description For My Site » Rank Math

    We need a solution where it will use:
    1. Content from the SEO Description field
    If that is missing, then:
    2. Template From General Settings in WordPress Dashboard > Rank Math > Titles & Meta > Products
    3. Product except

    Hello,

    Please remove the filter and replace it with this one:

    /**
     * Use the Description from Global Setting, if the description is missing in the Post metabox
     */
    add_action( 'rank_math/frontend/description', function( $description ) {
     global $post;
     $desc = RankMath\Post::get_meta( 'description', $post->ID );
    
     if ( is_product() && (empty($desc))) {
     $desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
     if ( $desc ) {
     return RankMath\Helper::replace_vars( $desc, $post );
     }
     }
    
     return $description;
    });

    With that filter, you can still prioritize the meta description in the Rank Math meta box while editing your products.

    Then for the rest of them, they will use the meta description template in Titles & Meta settings.

    Hope that helps.

    Unfortunately, the code you provided didn’t produce the results we wanted.
    It is still showing the short product description instead of the template

    Hello,

    Could you please confirm whether you have checked the product description using its source code?

    The filter applies when the product loads, so the description displayed while editing your product could still display the short description.

    If the meta description in the source code is still from the short description, then we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.

    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,

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

The ticket ‘Meta description template instead of short description’ is closed to new replies.