Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created October 7, 2016 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/507f9fd5829ef02ae3e2db7981eadf6f to your computer and use it in GitHub Desktop.
Save billerickson/507f9fd5829ef02ae3e2db7981eadf6f to your computer and use it in GitHub Desktop.
<?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