Excerpt overrides automatic single description

#586145
  • Resolved Will Robinson
    Rank Math free

    Hi there

    If I go to Rank Math -> Titles & Meta and change my default Single Post Description to something else (e.g. %customfield(seo_summary)%) but then manually add an excerpt to the post (Screen Options -> check the Excerpt box) then the default Single Post Description is ignored and the Excerpt is used instead. Is there a way to override the excerpt?

    Unfortunately, my theme uses the Excerpt in the page design so I can’t clear that on every post.

    Thanks.

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    In this case, you can use this filter on your site to force the Single Post Description even if there’s an excerpt already set

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

    Here’s how you can add a filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Please note that the filter may not be visible while editing your posts as it only works when they load in a browser. Once done, clear your website’s cache and check the published post meta description via the page’s source code.

    You can check the final output of the meta description here:
    https://rankmath.com/tools/meta-tag-analyzer/

    Hope that helps.

    Thank you.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this ticket.