Filter the description used in Schema markup

Need help with this?
Purchase All in One SEO Pack Pro to get dedicated support from us.

Buy Now

By default, All in One SEO Pack uses the SEO Description for the description in Schema markup on Posts and Pages.  If there’s no SEO Description then we will use the Post Excerpt.

This filter can be used to change this behavior to use the Post Excerpt or Post Content (instead of the SEO Description):

function aioseop_modify_schema_description( $data ) {
     global $post;
     if ( ! empty( $post->post_excerpt ) ) {
          $post_description = $post->post_excerpt;  // Use the post excerpt if one exists
     } else {
          $post_description = $post->post_content;  // Use the post content if there's no post excerpt
     }
     $data['description'] = $post_description;

     return $data;
}
add_filter( 'aioseop_schema_class_data_AIOSEOP_Graph_WebPage', 'aioseop_modify_schema_description' );
add_filter( 'aioseop_schema_class_data_AIOSEOP_Graph_Article', 'aioseop_modify_schema_description' );

You can use WordPress Conditional Tags if you want to control whether this is only used for Pages or only for Posts.

For instructions on how to use this code, please refer to our FAQ here.

  • Was this helpful ?
  • YesNo
[i]
[i]
Skip to toolbar