Jetpack_SEO_Posts

Class containing utility static methods for managing SEO custom descriptions for Posts and Pages.

Defined (1)

The class is defined in the following location(s).

/modules/seo-tools/jetpack-seo-posts.php  
  1. class Jetpack_SEO_Posts { 
  2. /** 
  3. * Key of the post meta value that will be used to store post custom description. 
  4. */ 
  5. const DESCRIPTION_META_KEY = 'advanced_seo_description'; 
  6.  
  7. /** 
  8. * Build meta description for post SEO. 
  9. * @param WP_Post $post Source of data for custom description. 
  10. * @return string Post description or empty string. 
  11. */ 
  12. public static function get_post_description( $post ) { 
  13. if ( empty( $post ) ) { 
  14. return ''; 
  15.  
  16. if ( post_password_required() || ! is_singular() ) { 
  17. return ''; 
  18.  
  19. // Business users can overwrite the description 
  20. $custom_description = self::get_post_custom_description( $post ); 
  21.  
  22. if ( ! empty( $custom_description ) ) { 
  23. return $custom_description; 
  24.  
  25. if ( ! empty( $post->post_excerpt ) ) { 
  26. return $post->post_excerpt; 
  27.  
  28. return $post->post_content; 
  29.  
  30. /** 
  31. * Returns post's custom meta description if it is set, and if 
  32. * SEO tools are enabled for current blog. 
  33. * @param WP_Post $post Source of data for custom description 
  34. * @return string Custom description or empty string 
  35. */ 
  36. public static function get_post_custom_description( $post ) { 
  37. if ( empty( $post ) ) { 
  38. return ''; 
  39.  
  40. $custom_description = get_post_meta( $post->ID, self::DESCRIPTION_META_KEY, true ); 
  41.  
  42. if ( empty( $custom_description ) || ! Jetpack_SEO_Utils::is_enabled_jetpack_seo() ) { 
  43. return ''; 
  44.  
  45. return $custom_description;