Skip to content

Commit df4d33a

Browse files
committed
Merge pull request Automattic#1265 from aheckler/issue-1236
Use image for og:image on image attachment pages
2 parents 3841812 + 712a3fa commit df4d33a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

functions.opengraph.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,14 @@ function jetpack_og_get_image( $width = 200, $height = 200, $max_images = 4 ) {
148148
if ( is_singular() && !is_home() ) {
149149
global $post;
150150
$image = '';
151+
152+
// Grab obvious image if $post is an attachment page for an image
153+
if ( is_attachment( $post->ID ) && substr( $post->post_mime_type, 0, 5) == 'image' ) {
154+
$image = wp_get_attachment_url( $post->ID );
155+
}
151156

152157
// Attempt to find something good for this post using our generalized PostImages code
153-
if ( class_exists( 'Jetpack_PostImages' ) ) {
158+
if ( ! $image && class_exists( 'Jetpack_PostImages' ) ) {
154159
$post_images = Jetpack_PostImages::get_images( $post->ID, array( 'width' => $width, 'height' => $height ) );
155160
if ( $post_images && !is_wp_error( $post_images ) ) {
156161
$image = array();

0 commit comments

Comments
 (0)