Support

Account

Home Forums General Issues Replace iframe code in ACF

Solved

Replace iframe code in ACF

  • Hey Community,
    I have a snippet with which I can add product videos as a featured image in WooCommerce.
    But I need a custom field in the code.

    I think oEmbed will be the right one here? –> https://ibb.co/m69zh1B

    But no matter what I try to exchange src = “XXX” I always get an error message.

        $output = '<div class="woocommerce-product-gallery images">';
            // Replace your iframe code from youtube here.
        $output .= '<iframe width="956" height="538" src="https://www.youtube.com/embed/aqz-KE-bpKQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
        $output .= '</div>';

    Thanks, Karsten

  • 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;
    }
  • i found the solution!

    After hours of searching, I found a post on stackoverflow.com

    1) create text field in acf. example : text field name is video_url

    2) Please enter a youtube video link in acf text field.

    3) show anywhere in wordpress template page

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

The topic ‘Replace iframe code in ACF’ is closed to new replies.