Changeset 193772 in webkit


Ignore:
Timestamp:
Dec 8, 2015, 12:43:33 PM (10 years ago)
Author:
Jon Davis
Message:

Fix social meta for home page.
https://bugs.webkit.org/show_bug.cgi?id=151764

Reviewed by Timothy Hatcher.

  • wp-content/plugins/social-meta.php:
Location:
trunk/Websites/webkit.org
Files:
2 edited

Legend:

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

    r193677 r193772  
     12015-12-08  Jonathan Davis  <jond@apple.com>
     2
     3        Fix social meta for home page.
     4        https://bugs.webkit.org/show_bug.cgi?id=151764
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * wp-content/plugins/social-meta.php:
     9
    1102015-12-07  Jonathan Davis  <jond@apple.com>
    211
  • trunk/Websites/webkit.org/wp-content/plugins/social-meta.php

    r192897 r193772  
    88*/
    99
    10 add_action('wp_head', function() { ?>
    11     <?php
     10add_action('wp_head', function() {
     11   
     12    $title = get_the_title();
     13    $description = get_the_excerpt();
     14    $type = 'article';
     15   
     16    $categories = array();
     17    $tags = array();
     18    $image_url = '';
     19    $twitter_handle = '';
     20   
     21    if (is_front_page() || is_home()) {
     22        $title = get_bloginfo('name');
     23        $description = get_bloginfo('description');
     24        $type = 'website';     
     25    }
     26   
     27    if (is_single()) {
    1228        $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'large' );
    1329        $image_url = $image_src[0];
    14     ?>
     30   
     31        $categories = wp_get_object_terms(get_the_ID(), 'category', array('fields' => 'names'));
     32        $tags = wp_get_object_terms(get_the_ID(), 'post_tag', array('fields' => 'names'));
     33
     34        // Post author data is not available in wp_head filter context
     35        $post = get_post();
     36        $twitter_handle = get_the_author_meta('twitter', $post->post_author);
     37    }
     38   
     39?>
    1540
    1641    <!-- Schema.org markup -->
    17     <meta itemprop="name" content="<?php the_title(); ?>">
    18     <meta itemprop="description" content="<?php the_excerpt(); ?>">
    19     <?php if ( $image_url ): ?>
    20     <meta itemprop="image" content="<?php echo $image_url; ?>">
    21     <?php endif; ?>
     42    <meta itemprop="name" content="<?php echo esc_attr($title); ?>">
     43<?php if ($description): ?>
     44    <meta itemprop="description" content="<?php echo esc_attr($description); ?>">
     45<?php endif; ?>
     46<?php if ($image_url): ?>
     47    <meta itemprop="image" content="<?php echo esc_url($image_url); ?>">
     48<?php endif; ?>
    2249
    2350    <!-- Twitter Card data -->
    2451    <meta name="twitter:card" content="summary_large_image">
    2552    <meta name="twitter:site" content="@webkit">
    26     <meta name="twitter:title" content="<?php the_title(); ?>">
    27     <meta name="twitter:description" content="<?php the_excerpt(); ?>">
    28     <?php if ( '' !== ( $twitter_handle = get_the_author_meta('twitter') ) ): ?>
    29     <meta name="twitter:creator" content="@<?php echo esc_html($twitter_handle); ?>">
    30     <?php endif; ?>
    31     <?php if ( $image_url ): // Twitter summary card with large image must be at least 280x150px ?>
    32     <meta name="twitter:image:src" content="<?php echo $image_url; ?>">
    33     <?php endif; ?>
     53    <meta name="twitter:title" content="<?php echo esc_attr($title); ?>">
     54<?php if ($description): ?>
     55    <meta name="twitter:description" content="<?php echo esc_attr($description); ?>">
     56<?php endif; ?>
     57<?php if ($twitter_handle): ?>
     58    <meta name="twitter:creator" content="@<?php echo esc_attr($twitter_handle); ?>">
     59<?php endif; ?>
     60<?php if ($image_url): // Twitter summary card with large image must be at least 280x150px ?>
     61    <meta name="twitter:image:src" content="<?php echo esc_url($image_url); ?>">
     62<?php endif; ?>
    3463
    3564    <!-- Open Graph data -->
    36     <meta property="og:title" content="<?php the_title(); ?>" />
    37     <meta property="og:type" content="article" />
     65    <meta property="og:title" content="<?php echo esc_attr($title); ?>" />
     66    <meta property="og:type" content="<?php echo esc_attr($type); ?>" />
    3867    <meta property="og:url" content="<?php the_permalink(); ?>" />
    39     <?php if ( $image_url ): ?>
    40     <meta itemprop="og:image" content="<?php echo $image_url; ?>">
    41     <?php endif; ?>
    42     <meta property="og:description" content="<?php the_excerpt(); ?>" />
     68<?php if ($image_url): ?>
     69    <meta itemprop="og:image" content="<?php echo esc_url($image_url); ?>">
     70<?php endif; ?>
     71<?php if ($description): ?>
     72    <meta property="og:description" content="<?php echo esc_attr($description); ?>" />
     73<?php endif; ?>
    4374    <meta property="og:site_name" content="<?php bloginfo('title'); ?>" />
    4475    <meta property="article:published_time" content="<?php the_time('c'); ?>" />
    4576    <meta property="article:modified_time" content="<?php the_modified_date('c'); ?>" />
    46     <?php
    47         $categories = wp_get_object_terms( get_the_ID(), 'category', array( 'fields' => 'names' ) );
    48         $tags = wp_get_object_terms( get_the_ID(), 'post_tag', array( 'fields' => 'names' ) );
     77<?php
     78    if (!empty($categories)):
     79        $section = array_shift($categories);      // The first category is used as the section
     80        $tags = array_merge($categories, $tags);  // The rest are prepended to the tag list
     81?>
     82    <meta property="article:section" content="<?php echo esc_attr($section); ?>" />
     83<?php
     84    endif;
    4985
    50         if ( ! empty($categories) ):
    51             $section = array_shift($categories);      // The first category is used as the section
    52             $tags = array_merge($categories, $tags);  // The rest are prepended to the tag list
    53     ?>
    54     <meta property="article:section" content="<?php echo esc_attr($section); ?>" />
    55     <?php
    56         endif;
    57 
    58         if ( ! empty($tags) ): foreach( $tags as $tag ):
    59     ?>
     86    if (!empty($tags)):
     87        foreach($tags as $tag):
     88?>
    6089    <meta property="article:tag" content="<?php echo esc_attr($tag); ?>" />
    61     <?php
    62         endforeach; endif;
    63     ?>
     90<?php
     91        endforeach;
     92    endif;
     93?>
    6494
    6595<?php
Note: See TracChangeset for help on using the changeset viewer.