Hey Euch allen,
Angenommen man hat drei "Post Typen":
- die standard Artikel
und zwei Custom Post Types
- Hunde
- Katzen
Links in den Standard Artikeln, als auch im CPT "Katze" sollen ganz regulär externe Links als Follow Links ausgeben. Externe Links im CPT Hunde jedoch sollen alle mit "nofollow" markiert werden.
Um alle external Links auf Nofollow zu setzen, könnte man dies ja so bewerkstelligen:
add_filter('the_content', 'auto_nofollow'); function auto_nofollow($content) { //return stripslashes(wp_rel_nofollow($content)); return preg_replace_callback('/<a>]+/', 'auto_nofollow_callback', $content);} function auto_nofollow_callback($matches) { $link = $matches[0]; $site_link = get_bloginfo('url'); if (strpos($link, 'rel') === false) { $link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link); } elseif (preg_match("%href=S(?!$site_link)%i", $link)) { $link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link); } return $link;}preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link); } return $link;}
http://www.wprecipes.com/wordpress-hack…in-post-content
(der besseren veranschaulichung wegen)
ZitatAlles anzeigenadd_filter('the_content', 'auto_nofollow');
function auto_nofollow($content) {
//return stripslashes(wp_rel_nofollow($content));
return preg_replace_callback('/<a>]+/', 'auto_nofollow_callback', $content);
}
function auto_nofollow_callback($matches) {
$link = $matches[0];
$site_link = get_bloginfo('url');
if (strpos($link, 'rel') === false) {
$link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link);
} elseif (preg_match("%href=S(?!$site_link)%i", $link)) {
$link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link);
}
return $link;
}
Ideen, Ansätze oder Lösungen - nur her damit
Liebe Grüße
Nomansland