• Resolved Denis

    (@theevoq)


    I found this code from you and it works, but it applies meta product description and for product categories and product attributes.

    If I paste the code, it takes the global meta description and inserts it into product, category and product attributes.

    When the code is inserted, the meta description is applied to these page categories:
    https://oilx.org/product-category/motornoe-maslo/ (category)
    https://oilx.org/brand/mobil/ (attribute)
    https://oilx.org/product/motornoe-maslo-cat-ngeo-40-208-l-105-3336/ (product)

    And I need it to apply only to the product:
    https://oilx.org/product/motornoe-maslo-cat-ngeo-40-208-l-105-3336/ (product)

    How can I make the code be used only for products?

    Regards Denis

    Code

    /**
    * 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 ( ! $desc ) {
    $desc = RankMath\Helper::get_settings( “titles.pt_{$post->post_type}_description” );
    if ( $desc ) {
    return RankMath\Helper::replace_vars( $desc, $post );
    }
    }

    return $description;
    });

Viewing 1 replies (of 1 total)
  • Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @theevoq,

    Thank you for contacting the support.

    If you want to apply the Global Description only to the products, please replace the filter that you are using with this one:

    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;
    });

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

Viewing 1 replies (of 1 total)
  • The topic ‘A short description of a product is inserted in the meta description’ is closed to new replies.