Support » Plugin: AMP for WordPress » Issue with post format ‘Video’ type in AMP version

  • Resolved ajentertainments

    (@ajentertainments)


    Hi, I installed the ‘AMP for WordPress’ Plugin from WordPress, When I visited the amp URL of the posts, the posts which I have chosen ‘video’ as the format and not format ‘standard’, the video which I have added (which is a YouTube link) is not shown instead only the featured image which I had uploaded is shown. For a non-AMP version, the video will be shown instead of the featured image. I would like this to happen for the AMP version as well.

    Since it is very difficult to go back and change 100’s of video format type to standard format type and replace it to post type then embedd the youtube code on each posts, will you be kind enough to guide me how to fix this issue, please ?

    Non-AMP Link: http://bit.ly/2IHqSQJ
    Post Format: Video

    (PS:I have disabled the plugin for now since, I do not want the search engines to crawl through the AMP version and in case I cannot fix the issue, give a 404 later when I disable it)

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support Ryan Kienstra

    (@ryankienstra)

    Possible Workaround

    Hi @ajentertainments,
    Sure, that’s understandable that you’d want to avoid changing the format of hundreds of posts.

    If you’re willing to put some code in your theme or a plugin, here’s a possible approach that worked for me locally:

    1. On posts with the format of ‘video,’ prevent the featured image from displaying:

    
    /**
     * On AMP endpoints for posts with a 'video' format, don't display a featured image.
     *
     * @param string  $markup The markup of the post thumbnail.
     * @param int     $post_id The post ID.
     * @return string $markup The filtered markup.
     */
    add_filter( 'post_thumbnail_html', function( $markup, $post_id ) {
    	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && ( 'video' === get_post_format( $post_id ) ) ) {
    		return '';
    	}
    	return $markup;
    }, 10, 2 );
    

    2. On posts with the format of ‘video,’ display the YouTube video at the top of the post content:

    
    /**
     * On AMP endpoints for posts with a 'video' format, display the YouTube video at the top of the post.
     *
     * @param string  $markup The post content.
     * @return string $markup The filtered post content.
     */
    add_filter( 'the_content', function( $markup ) {
        	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && ( 'video' === get_post_format() ) ) {
    		return 'Video markup here' . $markup;
    	}
    	return $markup;
    } );
    

    In place of 'Video markup here', please put the logic that outputs the video. I couldn’t find the data for the YouTube video in the REST API response, so I’m not sure where it is:
    https://www.keralareviews.com/wp-json/wp/v2/posts/1576

    Still, I might not have understood your needs.

    For reference, here’s the method in the AMP plugin that creates the featured image markup:
    https://github.com/Automattic/amp-wp/blob/730043bd769ece3f9104c8c1da36fb983a5ae284/includes/templates/class-amp-post-template.php#L328

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.