Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m hoping this gets merged soon:
    https://github.com/Automattic/facebook-instant-articles-wp/pull/433

    It fixed the problem for me.

    jkoon
    I was able to place the video above the content, but I had to edit one of the plugin files to get it to work, so it’s only a temporary fix until I find a better way.

    In the file, fb-instant-articles/class-instant-articles-post.php, I added:
    do_action( 'instant_articles_before_article_content', $this );
    on line 674, right after
    $document = apply_filters( 'instant_articles_parsed_document', $document );.

    Also, you have to specify the width and the height when adding the video, so my full functions.php code to add the video is:

    use Facebook\InstantArticles\Elements\SocialEmbed;
    
    function incl_video($ia_post) {
    	$instant_article = $ia_post->instant_article;
    	$post_id = $ia_post->get_the_id();
    	$iframe_string = get_post_meta( $post_id, 'video_embed_code', true );
    	if($iframe_string){
    		preg_match('/src="([^"]+)"/', $iframe_string, $match);
    		$video_url = $match[1];
    		$instant_article->addChild( SocialEmbed::create()->withSource($video_url)->withWidth(640)->withHeight(390) );
    	}
    }
    add_action( 'instant_articles_before_article_content', 'incl_video' );

    I was able to add the full Youtube tag with something like this using the SocialEmbed class instead.

    use Facebook\InstantArticles\Elements\SocialEmbed;
    add_action( 'instant_articles_after_transform_post', function ($ia_post) {
        $instant_article = $ia_post->instant_article;
        $post_id = $ia_post->get_the_id();
        $iframe_string = get_post_meta( $post_id, 'video_embed_code', true );
        preg_match('/src="([^"]+)"/', $iframe_string, $match);
        $video_url = $match[1];
        $instant_article->addChild( SocialEmbed::create()->withSource($video_url) );
    } );

    However, I’m still trying to get the video to appear before the content.

Viewing 3 replies - 1 through 3 (of 3 total)