包含带有动态src的iframe的PHP变量?

包含带有动态src的iframe的PHP变量?,php,html,iframe,wordpress-theming,advanced-custom-fields,Php,Html,Iframe,Wordpress Theming,Advanced Custom Fields,我正在我的站点上使用ACF,并试图设置一个PHP变量,该变量是一个包含ACF字段的iframe 我不知道为什么这不起作用,因为我可以回送变量并显示它,但它会抛出src(未知),否则呢 // Get spotify and set up tab if (have_rows('roster_media')): // loop through the rows of data while (have_rows('roster_media')): the_row(); $

我正在我的站点上使用ACF,并试图设置一个PHP变量,该变量是一个包含ACF字段的iframe

我不知道为什么这不起作用,因为我可以回送变量并显示它,但它会抛出src(未知),否则呢

// Get spotify and set up tab
if (have_rows('roster_media')):
    // loop through the rows of data
    while (have_rows('roster_media')): the_row();
        $spotify_uri = get_sub_field('rm_sp_link');
        echo $spotify_uri;
        $url = $spotify_uri;
        echo $url;
    endwhile;
else:
// no rows found
endif;

$rm_sp = '<iframe src="'.$url.'" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>';
//获取spotify和设置选项卡
如果(有行(“花名册\媒体”):
//循环遍历数据行
while(have_rows(“花名册_媒体”):the_row();
$spotify_uri=get_sub_字段('rm_sp_link');
echo$spotify_uri;
$url=$spotify_uri;
echo$url;
结束时;
其他:
//找不到行
endif;
$rm_sp='';
然后在稍后的页面中,我将通过以下方式致电:

<?php

$count = 0;
foreach ($embed_links as $e) {

    if ($count==0) {
        $rm_act = " active show";
    } else {
        $rm_act = "";
    }

    $content;

    if ($e['embed_platform']['value'] === "rm_sp") {
        $content ='<div class="rm-video">'.$rm_sp.'</div>';   
    } else if ($e['embed_platform']['value']==="rm_vid") {
        $content = '<div class="rm-video">'.$rm_vid.'</div>';
    }

    echo '<div class="tab-pane'.$rm_act.'" id="'.$e['embed_platform']['value'].'" role="tabpanel">'.$content.'</div>';
    $count++;
}

?>

我确信这是最糟糕的方法,但它目前对我有效,因为我没有其他想法。我使用jQuery来实现这一点

在while循环中,我添加了:

$spotify_uri = get_sub_field('rm_sp_link');
echo '<div id="spot_id">'.$spotify_uri.'</div>';

显然,#spot_id也需要对用户隐藏。

对于任何想知道的人来说,我目前正在使用jQuery(我认为这不是最好的方法,但对我来说是有效的)。
  if ($("#spot_id")[0]){
    // Do something if class exists
    spotifyUri = $("#spot_id").text();
    console.log(spotifyUri);
    $("#spot_iframe").attr('src' , $("#spot_iframe").attr('src') + spotifyUri);
  } else {
      // Do something if class does not exist
  }