Skip to content

Instantly share code, notes, and snippets.

@bogdanpopa90
Created September 18, 2017 09:37
Show Gist options
  • Save bogdanpopa90/2504e43aa0a591f4c3495c6bff5be105 to your computer and use it in GitHub Desktop.
Save bogdanpopa90/2504e43aa0a591f4c3495c6bff5be105 to your computer and use it in GitHub Desktop.
Function that adds target blank to external links in WordPress
function is_external_url( $url ) {
$link_url = parse_url( $url );
$home_url = parse_url( home_url() );
if ( ! empty( $link_url['host'] ) ) {
if ( $link_url['host'] !== $home_url['host'] ) {
return 'target="_blank"';
}
}
}
@Monica3000
Copy link

It does not works !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment