Home › Forums › General Issues › Replace iframe code in ACF › Reply To: Replace iframe code in ACF
this doesn’t give me an error, but nothing is shown …
function ts_add_iframe_video() {
$output = '<div class="woocommerce-product-gallery images">';
$iframe = get_field('produktvideo-url');
// Use preg_match to find iframe src.
preg_match('/src="(.+?)"/', $iframe, $matches);
$src = $matches[1];
// Add extra parameters to src and replcae HTML.
$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"; allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen';
$iframe = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $iframe);
// Replace your iframe code from youtube here.
$output .= 'echo $iframe;';
$output .= '</div>';
echo $output;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.