Sometimes, we need to set different excerpts for showing posts on the blog page. In this post, we are going to share a piece of code that works perfectly to change a posts' excerpt programmatically.
function rankmath_post_excerpt(){
$id = get_the_ID();
$post_type = get_post_type( get_the_ID() );
if ($post_type == 'post') {
$meta_description = get_post_meta($id,'rank_math_description',true);
return $meta_description;
}else{
return;
}
}
function check_for_rankmath_activation(){
if ( is_plugin_active( 'seo-by-rank-math/rank-math.php' ) ){
add_filter('get_the_excerpt', 'rankmath_post_excerpt' );
add_filter('the_excerpt', 'rankmath_post_excerpt' );
}
}
add_action('init','check_for_rankmath_activation');
Comments
Post a Comment