¿Está buscando una forma de agregar nofollow a enlaces específicos o a todos los enlaces en the_content? Si bien probablemente exista un plugin para esto, hemos creado un fragmento de código rápido que puede usar para agregar nofollow a enlaces específicos o a todos los enlaces en WordPress.
Instrucciones:
Todo lo que tienes que hacer es agregar este código al archivo functions.php de tu tema o a un plugin específico del sitio:
function example_link_nofollow( $content ) {
$url ='http://example.com';
$content = str_replace( '<a href="'.$url.'', '<a rel="nofollow" href="'.$url.'', $content );
return $content;
}
add_filter('the_content','example_link_nofollow');
El código anterior agregará nofollow a enlaces específicos con la URL mencionada anteriormente. Para agregar nofollow a todos los enlaces dentro de the_content(), necesita agregar el siguiente código:
function example_all_links_nofollow( $content ){
$content = str_replace( '<a href="', '<a rel="nofollow" href="', $content );
return $content;
}
add_filter('the_content','example_all_links_nofollow');
Nota: Si es la primera vez que agregas fragmentos de código en WordPress, consulta nuestra guía sobre cómo agregar fragmentos de código correctamente en WordPress, para que no rompas accidentalmente tu sitio.
Si te gustó este fragmento de código, considera echar un vistazo a nuestros otros artículos en el sitio como: los 24 mejores temas de WordPress para educación y los 8 mejores plugins de reseñas de WordPress.
Hola amigo,
Primero, gracias por tu solución... pero tengo una pregunta... tu primer código se usa para una URL específica, por ejemplo, "http://example.com"... pero ¿y si necesito agregarlo a algunas URLs? "http://example1.com", "http://example2.com" y "http://example3.com"
¿Puedes ayudarme con esto?
¡Por ahora, muchas gracias! 🙂