Advanced Custom Fields plugin : displaying a YouTube video

On my page, I have many fields text area fields containing text, and one WYSIWYG field containing a YouTube video (I need it to be WYSIWYG because otherwise only the URL of the video would show, not the video itself).

Problem: my text area fields have no tags other than br tags in them, whereas my WYSIWYG is full of p tags, creating layout misalignments.

Read More

If I remove p tags from the WYSIWYG field containing the video (using $strip = array(‘

‘,’

‘); echo str_replace($strip,”,$field);), then the iframe of the video becomes invisible, meaning it’s there but it’s gray in Firebug and doesn’t show on the page.

Any suggestions?

Related posts

2 comments

  1. You can try using wp_oembed_get and a textfield. You add the youtube url in the textfield.

    Assuming the field name is youtube_url, your code will be something like:

    if( get_field('youtube_url') ){
      $embed_code = wp_oembed_get( get_field('youtube_url') );
      echo $embed_code;
    }
    
  2. you can create text type field in Advance custom field

    $yt=get_field('youtube_url');//inside in loop
    if( '' != $yt)
    echo $GLOBALS['wp_embed']->autoembed( $yt );//youtube video iframe
    

Comments are closed.