Fixed Open Graph meta data and image entries.
authorjond@apple.com <jond@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jun 2016 18:12:23 +0000 (18:12 +0000)
committerjond@apple.com <jond@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jun 2016 18:12:23 +0000 (18:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159167.

Reviewed by Timothy Hatcher.

This patch addresses Open Graph meta data issues:

- Added a high-resolution PNG of the WebKit logo because Facebook doesn't support SVG images
- Uses the first image of a page or post if not featured image is set
- Article date/time information should not be given for the homepage
- Added Facebook admins as per the Facebook Open Graph debugger

* wp-content/plugins/social-meta.php:
* wp-content/themes/webkit/images/ogimage.png: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202577 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/webkit.org/ChangeLog
Websites/webkit.org/wp-content/plugins/social-meta.php
Websites/webkit.org/wp-content/themes/webkit/images/ogimage.png [new file with mode: 0644]

index 39fb645..d75b4e4 100644 (file)
@@ -1,3 +1,20 @@
+2016-06-28  Jon Davis  <jond@apple.com>
+
+        Fixed Open Graph meta data and image entries.
+        https://bugs.webkit.org/show_bug.cgi?id=159167.
+
+        Reviewed by Timothy Hatcher.
+
+        This patch addresses Open Graph meta data issues:
+
+        - Added a high-resolution PNG of the WebKit logo because Facebook doesn't support SVG images
+        - Uses the first image of a page or post if not featured image is set
+        - Article date/time information should not be given for the homepage
+        - Added Facebook admins as per the Facebook Open Graph debugger
+
+        * wp-content/plugins/social-meta.php:
+        * wp-content/themes/webkit/images/ogimage.png: Added.
+
 2016-06-27  Dean Jackson  <dino@apple.com>
 
         Updated content for the color blog post.
index 37ec606..692762e 100644 (file)
@@ -8,34 +8,50 @@ Author URI:  http://webkit.org
 */
 
 add_action('wp_head', function() {
-    
+
     $title = get_the_title();
     $description = get_the_excerpt();
     $type = 'article';
-    
+
     $categories = array();
     $tags = array();
-    $image_url = get_stylesheet_directory_uri() . '/images/webkit.svg';
+    $image_url = get_stylesheet_directory_uri() . '/images/ogimage.png';
     $twitter_handle = '';
-    
+    $published_time = '';
+    $modified_time = '';
+
+    $fb_admins = array(
+        'Jon Davis' => '1085088865',
+        'Tim Hatcher' => '854565306'
+    );
+
     if (is_front_page() || is_home()) {
         $title = get_bloginfo('name');
         $description = get_bloginfo('description');
-        $type = 'website';      
+        $type = 'website';
     }
-    
+
     if (is_single()) {
-        $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'large' );
-        $image_url = $image_src[0];
-    
+
+        $post = get_post();
+
+        if ( has_post_thumbnail() ) {
+            $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'large' );
+            $image_url = $image_src[0];
+        } else {
+            preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
+            if ($matches[1][0]) $image_url = $matches[1][0];
+        }
+
         $categories = wp_get_object_terms(get_the_ID(), 'category', array('fields' => 'names'));
         $tags = wp_get_object_terms(get_the_ID(), 'post_tag', array('fields' => 'names'));
 
         // Post author data is not available in wp_head filter context
-        $post = get_post();
         $twitter_handle = get_the_author_meta('twitter', $post->post_author);
+        $published_time = get_the_time('c');
+        $modified_time = get_the_modified_date('c');
     }
-    
+
 ?>
 
     <!-- Schema.org markup -->
@@ -62,35 +78,44 @@ add_action('wp_head', function() {
 <?php endif; ?>
 
     <!-- Open Graph data -->
-    <meta property="og:title" content="<?php echo esc_attr($title); ?>" />
-    <meta property="og:type" content="<?php echo esc_attr($type); ?>" />
-    <meta property="og:url" content="<?php the_permalink(); ?>" />
+    <meta property="og:title" content="<?php echo esc_attr($title); ?>">
+    <meta property="og:type" content="<?php echo esc_attr($type); ?>">
+    <meta property="og:url" content="<?php the_permalink(); ?>">
 <?php if ($image_url): ?>
     <meta itemprop="og:image" content="<?php echo esc_url($image_url); ?>">
 <?php endif; ?>
 <?php if ($description): ?>
-    <meta property="og:description" content="<?php echo esc_attr($description); ?>" />
+    <meta property="og:description" content="<?php echo esc_attr($description); ?>">
+<?php endif; ?>
+    <meta property="og:site_name" content="<?php bloginfo('title'); ?>">
+<?php if ($published_time): ?>
+    <meta property="article:published_time" content="<?php echo $published_time; ?>">
+<?php endif; ?>
+<?php if ($modified_time): ?>
+    <meta property="article:modified_time" content="<?php echo $modified_time; ?>">
 <?php endif; ?>
-    <meta property="og:site_name" content="<?php bloginfo('title'); ?>" />
-    <meta property="article:published_time" content="<?php the_time('c'); ?>" />
-    <meta property="article:modified_time" content="<?php the_modified_date('c'); ?>" />
 <?php
     if (!empty($categories)):
         $section = array_shift($categories);      // The first category is used as the section
         $tags = array_merge($categories, $tags);  // The rest are prepended to the tag list
 ?>
-    <meta property="article:section" content="<?php echo esc_attr($section); ?>" />
+    <meta property="article:section" content="<?php echo esc_attr($section); ?>">
 <?php
     endif;
 
     if (!empty($tags)):
         foreach($tags as $tag):
 ?>
-    <meta property="article:tag" content="<?php echo esc_attr($tag); ?>" />
-<?php 
-        endforeach; 
+    <meta property="article:tag" content="<?php echo esc_attr($tag); ?>">
+<?php
+        endforeach;
     endif;
-?>
 
+    if (!empty($fb_admins)):
+        foreach($fb_admins as $id):
+?>
+    <meta property="fb:admins" content="<?php echo esc_attr($id); ?>">
 <?php
+        endforeach;
+    endif;
 });
\ No newline at end of file
diff --git a/Websites/webkit.org/wp-content/themes/webkit/images/ogimage.png b/Websites/webkit.org/wp-content/themes/webkit/images/ogimage.png
new file mode 100644 (file)
index 0000000..6cee20c
Binary files /dev/null and b/Websites/webkit.org/wp-content/themes/webkit/images/ogimage.png differ