Skip to content

Instantly share code, notes, and snippets.

@Tmeister
Created March 8, 2017 19:28
Show Gist options
  • Save Tmeister/bf3e177e11de57d3f73fc48388ccdc31 to your computer and use it in GitHub Desktop.
Save Tmeister/bf3e177e11de57d3f73fc48388ccdc31 to your computer and use it in GitHub Desktop.
Thrive Content Editor - Add nofollow to external links
<?php
function add_nofollow( $content ) {
$re = '/<a(.*)>/iU';
preg_match_all( $re, $content, $matches );
$domain = get_bloginfo( 'url' );
foreach ( $matches[0] as $link ) {
if ( strpos( $link, $domain ) === false ) {
if ( strpos( $link, 'nofollow' ) === false ) {
$new_link = str_replace( '>', ' rel="nofollow">', $link );
$content = str_replace( $link, $new_link, $content );
}
}
}
return $content;
}
add_filter( 'tcb_clean_frontend_content', 'add_nofollow' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment