Title: [193772] trunk/Websites/webkit.org
- Revision
- 193772
- Author
- j...@apple.com
- Date
- 2015-12-08 12:43:33 -0800 (Tue, 08 Dec 2015)
Log 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:
Modified Paths
Diff
Modified: trunk/Websites/webkit.org/ChangeLog (193771 => 193772)
--- trunk/Websites/webkit.org/ChangeLog 2015-12-08 20:42:42 UTC (rev 193771)
+++ trunk/Websites/webkit.org/ChangeLog 2015-12-08 20:43:33 UTC (rev 193772)
@@ -1,3 +1,12 @@
+2015-12-08 Jonathan Davis <j...@apple.com>
+
+ 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:
+
2015-12-07 Jonathan Davis <j...@apple.com>
Implemented a workaround for sharp SVG WebKit logo.
Modified: trunk/Websites/webkit.org/wp-content/plugins/social-meta.php (193771 => 193772)
--- trunk/Websites/webkit.org/wp-content/plugins/social-meta.php 2015-12-08 20:42:42 UTC (rev 193771)
+++ trunk/Websites/webkit.org/wp-content/plugins/social-meta.php 2015-12-08 20:43:33 UTC (rev 193772)
@@ -7,60 +7,90 @@
Author URI: http://webkit.org
*/
-add_action('wp_head', function() { ?>
- <?php
+add_action('wp_head', function() {
+
+ $title = get_the_title();
+ $description = get_the_excerpt();
+ $type = 'article';
+
+ $categories = array();
+ $tags = array();
+ $image_url = '';
+ $twitter_handle = '';
+
+ if (is_front_page() || is_home()) {
+ $title = get_bloginfo('name');
+ $description = get_bloginfo('description');
+ $type = 'website';
+ }
+
+ if (is_single()) {
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'large' );
$image_url = $image_src[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);
+ }
+
+?>
+
<!-- Schema.org markup -->
- <meta itemprop="name" content="<?php the_title(); ?>">
- <meta itemprop="description" content="<?php the_excerpt(); ?>">
- <?php if ( $image_url ): ?>
- <meta itemprop="image" content="<?php echo $image_url; ?>">
- <?php endif; ?>
+ <meta itemprop="name" content="<?php echo esc_attr($title); ?>">
+<?php if ($description): ?>
+ <meta itemprop="description" content="<?php echo esc_attr($description); ?>">
+<?php endif; ?>
+<?php if ($image_url): ?>
+ <meta itemprop="image" content="<?php echo esc_url($image_url); ?>">
+<?php endif; ?>
<!-- Twitter Card data -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@webkit">
- <meta name="twitter:title" content="<?php the_title(); ?>">
- <meta name="twitter:description" content="<?php the_excerpt(); ?>">
- <?php if ( '' !== ( $twitter_handle = get_the_author_meta('twitter') ) ): ?>
- <meta name="twitter:creator" content="@<?php echo esc_html($twitter_handle); ?>">
- <?php endif; ?>
- <?php if ( $image_url ): // Twitter summary card with large image must be at least 280x150px ?>
- <meta name="twitter:image:src" content="<?php echo $image_url; ?>">
- <?php endif; ?>
+ <meta name="twitter:title" content="<?php echo esc_attr($title); ?>">
+<?php if ($description): ?>
+ <meta name="twitter:description" content="<?php echo esc_attr($description); ?>">
+<?php endif; ?>
+<?php if ($twitter_handle): ?>
+ <meta name="twitter:creator" content="@<?php echo esc_attr($twitter_handle); ?>">
+<?php endif; ?>
+<?php if ($image_url): // Twitter summary card with large image must be at least 280x150px ?>
+ <meta name="twitter:image:src" content="<?php echo esc_url($image_url); ?>">
+<?php endif; ?>
<!-- Open Graph data -->
- <meta property="og:title" content="<?php the_title(); ?>" />
- <meta property="og:type" content="article" />
+ <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 $image_url; ?>">
- <?php endif; ?>
- <meta property="og:description" content="<?php the_excerpt(); ?>" />
+<?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); ?>" />
+<?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
- $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' ) );
-
- 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
- ?>
+<?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); ?>" />
- <?php
- endif;
+<?php
+ endif;
- if ( ! empty($tags) ): foreach( $tags as $tag ):
- ?>
+ if (!empty($tags)):
+ foreach($tags as $tag):
+?>
<meta property="article:tag" content="<?php echo esc_attr($tag); ?>" />
- <?php
- endforeach; endif;
- ?>
+<?php
+ endforeach;
+ endif;
+?>
<?php
});
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes