Changeset 202577 in webkit


Ignore:
Timestamp:
Jun 28, 2016 11:12:23 AM (8 years ago)
Author:
Jon Davis
Message:

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.
Location:
trunk/Websites/webkit.org
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Websites/webkit.org/ChangeLog

    r202534 r202577  
     12016-06-28  Jon Davis  <jond@apple.com>
     2
     3        Fixed Open Graph meta data and image entries.
     4        https://bugs.webkit.org/show_bug.cgi?id=159167.
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        This patch addresses Open Graph meta data issues:
     9
     10        - Added a high-resolution PNG of the WebKit logo because Facebook doesn't support SVG images
     11        - Uses the first image of a page or post if not featured image is set
     12        - Article date/time information should not be given for the homepage
     13        - Added Facebook admins as per the Facebook Open Graph debugger
     14
     15        * wp-content/plugins/social-meta.php:
     16        * wp-content/themes/webkit/images/ogimage.png: Added.
     17
    1182016-06-27  Dean Jackson  <dino@apple.com>
    219
  • trunk/Websites/webkit.org/wp-content/plugins/social-meta.php

    r202521 r202577  
    99
    1010add_action('wp_head', function() {
    11    
     11
    1212    $title = get_the_title();
    1313    $description = get_the_excerpt();
    1414    $type = 'article';
    15    
     15
    1616    $categories = array();
    1717    $tags = array();
    18     $image_url = get_stylesheet_directory_uri() . '/images/webkit.svg';
     18    $image_url = get_stylesheet_directory_uri() . '/images/ogimage.png';
    1919    $twitter_handle = '';
    20    
     20    $published_time = '';
     21    $modified_time = '';
     22
     23    $fb_admins = array(
     24        'Jon Davis' => '1085088865',
     25        'Tim Hatcher' => '854565306'
     26    );
     27
    2128    if (is_front_page() || is_home()) {
    2229        $title = get_bloginfo('name');
    2330        $description = get_bloginfo('description');
    24         $type = 'website';     
     31        $type = 'website';
    2532    }
    26    
     33
    2734    if (is_single()) {
    28         $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'large' );
    29         $image_url = $image_src[0];
    30    
     35
     36        $post = get_post();
     37
     38        if ( has_post_thumbnail() ) {
     39            $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'large' );
     40            $image_url = $image_src[0];
     41        } else {
     42            preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
     43            if ($matches[1][0]) $image_url = $matches[1][0];
     44        }
     45
    3146        $categories = wp_get_object_terms(get_the_ID(), 'category', array('fields' => 'names'));
    3247        $tags = wp_get_object_terms(get_the_ID(), 'post_tag', array('fields' => 'names'));
    3348
    3449        // Post author data is not available in wp_head filter context
    35         $post = get_post();
    3650        $twitter_handle = get_the_author_meta('twitter', $post->post_author);
     51        $published_time = get_the_time('c');
     52        $modified_time = get_the_modified_date('c');
    3753    }
    38    
     54
    3955?>
    4056
     
    6379
    6480    <!-- Open Graph data -->
    65     <meta property="og:title" content="<?php echo esc_attr($title); ?>" />
    66     <meta property="og:type" content="<?php echo esc_attr($type); ?>" />
    67     <meta property="og:url" content="<?php the_permalink(); ?>" />
     81    <meta property="og:title" content="<?php echo esc_attr($title); ?>">
     82    <meta property="og:type" content="<?php echo esc_attr($type); ?>">
     83    <meta property="og:url" content="<?php the_permalink(); ?>">
    6884<?php if ($image_url): ?>
    6985    <meta itemprop="og:image" content="<?php echo esc_url($image_url); ?>">
    7086<?php endif; ?>
    7187<?php if ($description): ?>
    72     <meta property="og:description" content="<?php echo esc_attr($description); ?>" />
     88    <meta property="og:description" content="<?php echo esc_attr($description); ?>">
    7389<?php endif; ?>
    74     <meta property="og:site_name" content="<?php bloginfo('title'); ?>" />
    75     <meta property="article:published_time" content="<?php the_time('c'); ?>" />
    76     <meta property="article:modified_time" content="<?php the_modified_date('c'); ?>" />
     90    <meta property="og:site_name" content="<?php bloginfo('title'); ?>">
     91<?php if ($published_time): ?>
     92    <meta property="article:published_time" content="<?php echo $published_time; ?>">
     93<?php endif; ?>
     94<?php if ($modified_time): ?>
     95    <meta property="article:modified_time" content="<?php echo $modified_time; ?>">
     96<?php endif; ?>
    7797<?php
    7898    if (!empty($categories)):
     
    80100        $tags = array_merge($categories, $tags);  // The rest are prepended to the tag list
    81101?>
    82     <meta property="article:section" content="<?php echo esc_attr($section); ?>" />
     102    <meta property="article:section" content="<?php echo esc_attr($section); ?>">
    83103<?php
    84104    endif;
     
    87107        foreach($tags as $tag):
    88108?>
    89     <meta property="article:tag" content="<?php echo esc_attr($tag); ?>" />
    90 <?php 
    91         endforeach; 
     109    <meta property="article:tag" content="<?php echo esc_attr($tag); ?>">
     110<?php
     111        endforeach;
    92112    endif;
     113
     114    if (!empty($fb_admins)):
     115        foreach($fb_admins as $id):
    93116?>
    94 
     117    <meta property="fb:admins" content="<?php echo esc_attr($id); ?>">
    95118<?php
     119        endforeach;
     120    endif;
    96121});
Note: See TracChangeset for help on using the changeset viewer.