Support

Account

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;
    }