2

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.

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?

2 Answers 2

3

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;
}
4
  • Doesn't seem to display anything on my computer...
    – drake035
    Commented Jul 15, 2013 at 13:19
  • Try adding a real youtube url in the wp_oembed_get parameter
    – RRikesh
    Commented Jul 16, 2013 at 4:37
  • Just tried, doesn't display anything either.
    – drake035
    Commented Jul 16, 2013 at 11:11
  • Had made a regex script to strip the url and make my own embed... nice find
    – Warface
    Commented Jun 10, 2014 at 18:59
0

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
4
  • Same comment: doesn't display anything on my computer.
    – drake035
    Commented Jul 15, 2013 at 13:19
  • did you define the text type field in acf with name 'youtube_url'? Commented Jul 15, 2013 at 13:44
  • No I did the other way around, I replace 'youtube_url' in your code by the name of the text field that I created and populated with a YouTube video URL.
    – drake035
    Commented Jul 15, 2013 at 14:54
  • ok, is this working know?youtube_url field type name in acf only was for example you can replace it by your own. Commented Jul 17, 2013 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.