A continuación una función para añadir automáticamente la etiqueta rel «nofollow» a todos los enlaces del content() sin necesidar de utilizar plugins en nuestro WordPress. La función wp_rel_nofollow que nos agiliza el trabajo, y no tenemos necesidad de crear una nueva función php con expresiones regulares.
A. Basta con que editéis el archivo functions.php de vuestro theme y añadir la siguiente función:
function nofollow_thecontent($text) { global $post; if( is_single() ) { $text = stripslashes(wp_rel_nofollow($text)); } return $text; } add_filter('the_content', 'nofollow_thecontent');
B. Y si queremos filtrar por categorÃa, y por ejemplo añadir nofollow a todos los enlaces excepto a los post que pertenezca a una o varias categorÃa:
function nofollow_thecontent($text) { global $post; if( is_single() && !in_category(6969) ) { $text = stripslashes(wp_rel_nofollow($text)); } return $text; } add_filter('the_content', 'nofollow_thecontent');
(*) Sustituye 6969 por el ID de la categorÃa/s tuyas.
De esta forma nuestro enlaces pasarán a tener la siguiente estructura (un ejemplo):
Hola esto es una <a rel="nofollow" href="http://www.dominio.com">prueba</a> de enlace en mi contenido.
Agradezco tu comentario 🤘