Skip to content

Instantly share code, notes, and snippets.

@jondcampbell
Created February 16, 2016 18:48
Show Gist options
  • Save jondcampbell/b3ce6d8cd4b575d5557c to your computer and use it in GitHub Desktop.
Save jondcampbell/b3ce6d8cd4b575d5557c to your computer and use it in GitHub Desktop.
check if an acf link field value is for our current site or an external link
<?php
$our_parsed_url = parse_url( site_url() );
$link_parsed_url = parse_url( get_sub_field( 'link' ) );
if ( $our_parsed_url['host'] === $link_parsed_url['host'] ) :
$external_link = false;
else :
$external_link = true;
endif;
?>
<a class="button" <?php if($external_link): echo'target="_blank"'; endif;?> href="<?php the_sub_field( 'link' ); ?>">Visit</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment