WordPress.org

Making WordPress.org

Changeset 2447


Ignore:
Timestamp:
02/02/2016 09:39:53 PM (4 years ago)
Author:
iandunn
Message:

Jetpack Tweaks: Set the default Open Graph image on single posts.

Fixes #1526
Props jeherve

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/jetpack-tweaks.php

    r2382 r2447  
    1212}
    1313add_filter( 'jetpack_open_graph_image_default', __NAMESPACE__ . '\default_og_image' );
     14
     15/**
     16 * Choose the default Open Graph image for single posts
     17 *
     18 * @param array $media
     19 * @param int   $post_id
     20 * @param array $args
     21 *
     22 * @return array
     23 */
     24function default_single_og_image( $media, $post_id, $args ) {
     25    if ( $media ) {
     26        return $media;
     27    }
     28
     29    if ( has_site_icon() ) {
     30        $image_url = get_site_icon_url();
     31    } else if ( has_header_image() ) {
     32        $image_url = get_header_image();
     33    } else {
     34        $image_url = default_og_image();
     35    }
     36
     37    return array( array(
     38        'type' => 'image',
     39        'from' => 'custom_fallback',
     40        'src'  => esc_url( $image_url ),
     41        'href' => get_permalink( $post_id ),
     42    ) );
     43}
     44add_filter( 'jetpack_images_get_images', __NAMESPACE__ . '\default_single_og_image', 10, 3 );
    1445
    1546/*
Note: See TracChangeset for help on using the changeset viewer.