jon-c
2/16/2016 - 6:48 PM

check if an acf link field value is for our current site or an external link

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>