最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Advanced Custom Fields oembed only outputs YouTube URL

programmeradmin4浏览0评论

Having the exact same problem as @Hjalmar on Advanced Custom Fields, but still no fix. Only the URL text displays.

Tried the original ACF oembed option:

<div class="embed-container">

    <?php echo get_field('video_embedd'); ?>

</div>

No luck.

Placed the YouTube embed URL in the ACF text field and outputting it into an HTML iframe:

<?php

$videoEmbeddPlease = get_field('video_embedd');

if (!empty($videoEmbeddPlease)): ?>

    <iframe width="560" height="315" src="<?php echo $videoEmbeddPlease?>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

<?php endif ?>

No luck.

Even tried the Advanced ACF example:

<?php

// get iframe HTML
$iframe = get_field('video_embedd');

// use preg_match to find iframe src
preg_match('/src="(.+?)"/', $iframe, $matches);
$src = $matches[1];

// add extra params to iframe src
$params = array(
'controls'    => 0,
'hd'        => 1,
'autohide'    => 1
);

$new_src = add_query_arg($params, $src);

$iframe = str_replace($src, $new_src, $iframe);

// add extra attributes to iframe html
$attributes = 'frameborder="0"';

$iframe = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $iframe);

// echo $iframe
echo $iframe;

?>

Even tried the WYSIWYG option.

<?php the_field('video_embedd'); ?>

Still! No embedded video display, just the YouTube URL text on the screen.

Any help would be incredible.

Thank you!

Having the exact same problem as @Hjalmar on Advanced Custom Fields, but still no fix. Only the URL text displays.

Tried the original ACF oembed option:

<div class="embed-container">

    <?php echo get_field('video_embedd'); ?>

</div>

No luck.

Placed the YouTube embed URL in the ACF text field and outputting it into an HTML iframe:

<?php

$videoEmbeddPlease = get_field('video_embedd');

if (!empty($videoEmbeddPlease)): ?>

    <iframe width="560" height="315" src="<?php echo $videoEmbeddPlease?>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

<?php endif ?>

No luck.

Even tried the Advanced ACF example:

<?php

// get iframe HTML
$iframe = get_field('video_embedd');

// use preg_match to find iframe src
preg_match('/src="(.+?)"/', $iframe, $matches);
$src = $matches[1];

// add extra params to iframe src
$params = array(
'controls'    => 0,
'hd'        => 1,
'autohide'    => 1
);

$new_src = add_query_arg($params, $src);

$iframe = str_replace($src, $new_src, $iframe);

// add extra attributes to iframe html
$attributes = 'frameborder="0"';

$iframe = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $iframe);

// echo $iframe
echo $iframe;

?>

Even tried the WYSIWYG option.

<?php the_field('video_embedd'); ?>

Still! No embedded video display, just the YouTube URL text on the screen.

Any help would be incredible.

Thank you!

Share Improve this question asked Jan 10, 2019 at 1:13 LukeLuke 11 gold badge1 silver badge2 bronze badges 2
  • You check ACF Support? – RiddleMeThis Commented Feb 12, 2019 at 19:49
  • @RiddleMeThis I have not. Probably should, shouldn't I? Can I just link to this post? – Luke Commented Feb 20, 2019 at 20:02
Add a comment  | 

2 Answers 2

Reset to default 1

Such happens when video is not publicly accessible. In my case the video was simply removed from YouTube by their author and ACF's oEmbed module was unable to get metadata to properly display video.

It's also possible that google is blocking the api request to fetch the embed data.

ACF uses the wp_oembed_get function which goes off and grabs metadata from Youtube before displaying the iframe.

Sometimes google may block your server or network if it thinks you have been making too many requests. Google will return the confirm you're not a robot page with the message

"Our systems have detected unusual traffic from your computer network"

发布评论

评论列表(0)

  1. 暂无评论