Custom folder for AMP templates
-
Hi
I have some trouble with generating AMP content using custom folder for AMP templates.So,
I have a folder “amp” and this code
add_theme_support( ‘amp’, array(
‘template_dir’ => ‘amp’,
));I don`t understand how I should code the template (for example single.php) in order to get amp compatible post content.
in the header.php in folder amp I added
<?php global $post;
$amp_post = new AMP_Post_Template($post);
?>single.php looks like below:
<?php include ‘header.php’; ?>
<div class=”amp-container”>
<main class=”main-amp-content”>
<article class=”amp-wp-article”>
<header class=”amp-wp-article-header”>
<h1 class=”amp-wp-title”><?php echo esc_html( $amp_post->get( ‘post_title’ ) ); ?></h1></header>
<?php
$featured_image = $amp_post->get( ‘featured_image’ );if ( empty( $featured_image ) ) {
return;
}$amp_html = $featured_image[‘amp_html’];
$caption = $featured_image[‘caption’];
?>
<figure class=”amp-wp-article-featured-image wp-caption”>
<?php echo $amp_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php if ( $caption ) : ?>
<p class=”wp-caption-text”>
<?php echo wp_kses_data( $caption ); ?>
</p>
<?php endif; ?>
</figure><div class=”amp-wp-article-content”>
<?php echo $amp_post->get( ‘post_amp_content’ );?>
</div><footer class=”amp-wp-article-footer”>
<?php $amp_post->load_parts( apply_filters( ‘amp_post_article_footer_meta’, array( ‘meta-taxonomy’, ‘meta-comments-link’ ) ) ); ?>
</footer>
</article>
</main></div>
<?php include ‘footer.php’; ?>
But images, iframes of my content are rendered incorrectly, they are just lost instead of being as amp-img and amp-iframe.
Can you please desribe me the way I should code the templates in my custon folder for AMP?
Thanks in advance!
The topic ‘Custom folder for AMP templates’ is closed to new replies.