-
-
Save billerickson/507f9fd5829ef02ae3e2db7981eadf6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* AMP Fallback Image | |
* If no image is specified, use a site-wide default. | |
* | |
*/ | |
function ea_amp_fallback_image( $data ) { | |
if( ! isset( $data['metadata']['image'] ) || empty( $data['metadata']['image'] ) ) { | |
$image = wp_get_attachment_image_src( ct_get_option( 'default_post_image_id' ), 'full' ); | |
if( $image && ! is_wp_error( $image ) && is_array( $image ) ) { | |
$data['metadata']['image'] = array( | |
'@type' => 'ImageObject', | |
'url' => $image[0], | |
'width' => $image[1], | |
'height' => $image[2], | |
); | |
} | |
} | |
return $data; | |
} | |
add_filter( 'amp_post_template_data', 'ea_amp_fallback_image' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment