Skip to content

Instantly share code, notes, and snippets.

@gstricklind
Created February 18, 2018 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gstricklind/b2dd7d5bd1b60a3b7a2f664f2d6b687f to your computer and use it in GitHub Desktop.
Save gstricklind/b2dd7d5bd1b60a3b7a2f664f2d6b687f to your computer and use it in GitHub Desktop.
Open ALL links in new tab for a custom post type or page template type
// use this code in your page template where needed
function gs_target_blank($content) {
$post_string = $content;
$post_string = str_replace('<a', '<a target="_blank"', $post_string);
return $post_string;
}
add_filter( 'the_content', 'gs_target_blank' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment