Forum Replies Created

Viewing 1 replies (of 1 total)
  • I have the same question as parazi7u…

    I got this snippet… I think I’m close, but not quite there yet. Any idea on how to convert into <amp-img>?

    function isa_amp_featured_img( $size = ‘medium’ ) {

    global $post;

    if ( has_post_thumbnail( $post->ID ) ) {

    $thumb_id = get_post_thumbnail_id( $post->ID );
    $img = wp_get_attachment_image_src( $thumb_id, $size );
    $img_src = $img[0];
    $w = $img[1];
    $h = $img[2];

    $alt = get_post_meta($post->ID, ‘_wp_attachment_image_alt’, true);

    if(empty($alt)) {
    $attachment = get_post( $thumb_id );
    $alt = trim(strip_tags( $attachment->post_title ) );
    } ?>
    <amp-img id=”feat-img” src=”<?php echo esc_url( $img_src ); ?>” <?php
    if ( $img_srcset = wp_get_attachment_image_srcset( $thumb_id, $size ) ) {
    ?> srcset=”<?php echo esc_attr( $img_srcset ); ?>” <?php
    }
    ?> alt=”<?php echo esc_attr( $alt ); ?>” width=”<?php echo $w; ?>” height=”<?php echo $h; ?>”>
    </amp-img>
    <?php
    }
    }

    function my_amp_set_custom_template( $file, $type, $post ) {
    if ( ‘single’ === $type ) {
    $file = get_stylesheet_directory() . ‘/amp/single.php’;
    }
    return $file;
    }
    add_filter( ‘amp_post_template_file’, ‘my_amp_set_custom_template’, 10, 3 );

Viewing 1 replies (of 1 total)