Preventing Global Meta Description Overwrite

#935039
  • Hello Support,

    I would like to inquire about how to prevent the global meta description from being overwritten when an excerpt is entered. Could you please guide me on how to configure this correctly?

    Looking forward to your response.

    Best regards,
    Hindistack

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

    Thank you for contacting Rank Math support.

    You will have to add the following filter to use the global description when an excerpt is present:

    add_action( 'rank_math/frontend/description', function( $description ) {
    	global $post;
    	$desc = RankMath\Post::get_meta( 'description', $post->ID );
    
    	if ( is_single()) {
    		 $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/

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

    Thank you Jaideep for your response. However, there is an issue.

    Currently, with the provided code, the excerpt does not override the global settings, which is expected behavior. However, I would like the meta description entered in the single post editor (as shown in the attached image) to take precedence. In this scenario, the meta description should reflect the editor’s input, but the current behavior still displays the global settings.

    Image –
    img

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this ticket.