Skip to content

Instantly share code, notes, and snippets.

@purzlbaum
Last active August 29, 2015 14:16
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 purzlbaum/333ee4db713dd9d2db44 to your computer and use it in GitHub Desktop.
Save purzlbaum/333ee4db713dd9d2db44 to your computer and use it in GitHub Desktop.
<?php
/*
Sets "external" class for external links and open them in a new tab/window
*/
function cs_bootstrap_external_link($text) {
$wpUrl = get_bloginfo('url');
$return = str_replace('href=', 'class="external" href=', $text);
$return = str_replace('class="external" target="_blank" href="' . $wpUrl . '', 'href="' . $wpUrl . '', $return);
$return = str_replace('class="external" target="_blank" href="#', 'href="#', $return);
return $return;
}
add_filter('the_content', 'cs_bootstrap_external_link');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment