Created
July 21, 2016 18:13
-
-
Save johnregan3/776e6fe518dcca2153f571191d4d9395 to your computer and use it in GitHub Desktop.
Add Featured Images to a WordPress AMP Template
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 | |
/** | |
* Allow custom actions in our AMP template. | |
*/ | |
function jr3_amp_add_custom_actions() { | |
add_filter( 'the_content', 'jr3_amp_add_featured_image' ); | |
} | |
add_action( 'pre_amp_render_post', 'jr3_amp_add_custom_actions' ); | |
/** | |
* Add Featured Image Support. | |
* | |
* @link https://github.com/Automattic/amp-wp#featured-image | |
*/ | |
function jr3_amp_add_featured_image( $content ) { | |
if ( has_post_thumbnail() ) { | |
// Just add the raw <img /> tag; the WP AMP sanitizer will take care of it later. | |
$image = sprintf( '<p class="jr3-featured-image">%s</p>', get_the_post_thumbnail() ); | |
$content = $image . $content; | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment