• Resolved tw1l1ght

    (@tw1l1ght)


    I write a template for CPT in setting, but still see the excerpt as a page description. How to bypass it?

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

    (@rankmathsupport)

    Hello @tw1l1ght,

    Thank you for contacting Rank Math support.

    When you have an excerpt, it will override the global settings and will be used for the meta description. To change this behavior, please add the following filter to your site:

    add_action( 'rank_math/frontend/description', function( $description ) {
    global $post;
    $desc = RankMath\Post::get_meta( 'description', $post->ID );
    if ( get_post_type() == 'Your Post Type') { //replace with the name of CPT
    $desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
    if ( $desc ) {
    return RankMath\Helper::replace_vars( $desc, $post );
    }
    }

    return $description;
    });

    Here is how to add a filter to your site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Please note that the correct description will be added in the front end. In the snippet editor, you will still see the manual description.

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

    Thread Starter tw1l1ght

    (@tw1l1ght)

    Hello @rankmathsupport

    It worked, but now an archive page is using the description of latest post instead of it own

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello tw1l1ght,

    Here is the modified filter that will only apply to the single posts of the post type, not the archive page:

    add_action( 'rank_math/frontend/description', function( $description ) {
    global $post;
    $desc = RankMath\Post::get_meta( 'description', $post->ID );
    if ( get_post_type() == 'Your Post Type' && is_single() ) { //replace with the name of CPT
    $desc = RankMath\Helper::get_settings( "titles.pt_{$post->post_type}_description" );
    if ( $desc ) {
    return RankMath\Helper::replace_vars( $desc, $post );
    }
    }

    return $description;
    });

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.