]*?\srel=['\"])(?![^'\"]*\bnofollow\b)|i" => "$1nofollow ", "|]*\srel=['\"])|i" => 'escape($text); return $text; } /* replace these */ /** * Adds rel nofollow string to all HTML A elements in content. * * @since 1.5.0 * * @param string $text Content that may contain HTML A elements. * @return string Converted content. */ function wp_rel_nofollow( $text ) { global $wpdb; // This is a pre save filter, so text is already escaped. $text = stripslashes($text); $text = preg_replace_callback('||i', 'wp_rel_nofollow_callback', $text); $text = $wpdb->escape($text); return $text; } /** * Callback to used to add rel=nofollow string to HTML A element. * * Will remove already existing rel="nofollow" and rel='nofollow' from the * string to prevent from invalidating (X)HTML. * * @since 2.3.0 * * @param array $matches Single Match * @return string HTML A Element with rel nofollow. */ function wp_rel_nofollow_callback( $matches ) { $text = $matches[1]; $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text); return ""; } ?>