Skip to content

Instantly share code, notes, and snippets.

@pshapiro
Last active March 15, 2016 20:54
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 pshapiro/2bbb4ad54d835db15e50 to your computer and use it in GitHub Desktop.
Save pshapiro/2bbb4ad54d835db15e50 to your computer and use it in GitHub Desktop.
Fix Schema Validation for WordPress AMP Plugin where posts don't have a featured image.
# Edit AMP Plugin file: amp/includes/class-amp-post-template.php
/*
Change this bit of code to the below uncommented code:
$image_metadata = $this->get_post_image_metadata();
if ( $image_metadata ) {
$metadata['image'] = $image_metadata;
}
$this->add_data_by_key( 'metadata', apply_filters( 'amp_post_template_metadata', $metadata, $this->post ) );
}
*/
$image_metadata = $this->get_post_image_metadata();
if ( $image_metadata ) {
$metadata['image'] = $image_metadata;
}
if(empty($metadata['image'])){
$metadata['image'] = array(
'@type' => 'ImageObject',
'url' => 'URL OF IMAGE',
'height' => 300,
'width' => 700,
);
}
$this->add_data_by_key( 'metadata', apply_filters( 'amp_post_template_metadata', $metadata, $this->post ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment