WordPress.org

Making WordPress.org

Changeset 4481


Ignore:
Timestamp:
12/04/2016 09:33:59 PM (18 months ago)
Author:
obenland
Message:

Plugin Directory: Enable richer social media integrations.

Props joostdevalk.
Fixes #2303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/functions.php

    r4478 r4481  
    1010namespace WordPressdotorg\Plugin_Directory\Theme;
    1111use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     12use WordPressdotorg\Plugin_Directory\Template;
    1213
    1314/**
     
    157158
    158159/**
     160 * Adds meta tags for richer social media integrations.
     161 */
     162function social_meta_data() {
     163    if ( ! is_singular( 'plugin' ) ) {
     164        return;
     165    }
     166
     167    $post_id = get_the_ID();
     168    $banner  = Template::get_plugin_banner( $post_id );
     169    $banner['banner_2x'] = $banner['banner_2x'] ? $banner['banner'] : false;
     170    $icon = Template::get_plugin_icon( $post_id );
     171
     172    printf( '<meta property="og:title" content="%s" />' . "\n", the_title_attribute( array( 'echo' => false, 'post' => $post_id ) ) );
     173    printf( '<meta property="og:description" content="%s" />' . "\n", esc_attr( strip_tags( get_the_excerpt( $post_id ) ) ) );
     174    printf( '<meta property="og:site_name" content="WordPress.org" />' . "\n" );
     175    printf( '<meta property="og:type" content="website" />' . "\n" );
     176    printf( '<meta property="og:url" content="%s" />' . "\n", esc_url( get_permalink( $post_id ) ) );
     177    printf( '<meta name="twitter:card" content="summary_large_image">' . "\n" );
     178    printf( '<meta name="twitter:site" content="@WordPress">' . "\n" );
     179
     180    if ( $banner['banner_2x'] ) {
     181        printf( '<meta name="twitter:image" content="%s" />' . "\n", $banner['banner_2x'] );
     182    }
     183    if ( isset( $banner['banner'] ) ) {
     184        printf( '<meta property="og:image" content="%s" />' . "\n", $banner['banner'] );
     185    }
     186    if ( ! $icon['generated'] && ( $icon['icon_2x'] || $icon['icon'] ) ) {
     187        printf( '<meta name="thumbnail" content="%s" />', $icon['icon_2x'] ?: $icon['icon'] );
     188    }
     189}
     190add_action( 'wp_head', __NAMESPACE__ . '\social_meta_data' );
     191
     192/**
    159193 * Adds hreflang link attributes to plugin pages.
    160194 *
Note: See TracChangeset for help on using the changeset viewer.