Created
February 16, 2016 18:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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