Support

Account

Home Forums Front-end Issues Strip iframe tags but output the url

Solved

Strip iframe tags but output the url

  • Hi,

    How can i strip the iframe tags so i only get the url from the iframe to display?

    <?php the_sub_field('embed_iframe')); ?>

  • Get the field value without formatting if this is an oembed field

    
    <?php $value = get_sub_field('embed_iframe', false)); ?>
    

    https://www.advancedcustomfields.com/resources/get_sub_field/

  • Hi John,

    It’s not a oEmbed field but a textarea. It’s for placing a Google Map on the site but i want to put the iframe tags around it myself so i only need the url(src) of the iframe.

    Google maps

  • In that case you would need to use string manipulation functions, or most likely regular expressions. The problem with these is that they may or may not work if the format of the content is altered

    
    $value = get_sub_field('embed_iframe', false));
    if (preg_match('/src="([^"]+)/', $value, $matches)) {
      $url = $matches[1];
    }
    
  • Hi John,

    I get no output? Do i something wrong? I have not changed the iframe content in the textarea but i dont get the src value.

    <?php 
    	$value = get_sub_field('embed_iframe', false);
    if (preg_match('/src="([^"]+)/', $value, $matches)) {
      $url = $matches[1];
    } ?>
  • 
    <?php 
    	$value = get_sub_field('embed_iframe', false);
    if (preg_match('/src="([^"]+)/', $value, $matches)) {
      $url = $matches[1];
    }
    
    echo $url;
    ?>
    
  • Hi John,

    Great that is doing the job, thank you for your help.

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

You must be logged in to reply to this topic.