you can use a find & replace trick like first find the "<a href=" in your variable and replace it with "<a rel='nofollow' href=". you can do this in php by using SYNTAX: str_ireplace("text to find","text to replace with","source text where to find the link"); PRACTICAL: $no_follow = str_ireplace("<a href=","<a rel='nofollow' href=",$variable); Regards.
@emilybarbie this one looks good.. will take a closer look later. @sweetguyzzz by you, the problem is... that the nofollow should be at the end of the <a tags... also just before > and not before href= etc... but thank you both
For the record it doesn't really matter what order tag attributes go in, so you can have the "rel" before the "href" if you want.
@xd2: and what if some one adda another rel="dofollow" behind the rel="nofollow" ? when they post a comment ? :S
I was stating it doesn't matter where in the tag it goes but if you was concerned about that then you should check and replace for dofollow first otherwise you would end up with duplicate attributes anyway. Anyway my thought didn't go that deep I just thought based on your post you had presumed that's where it had to go when in fact it doesn't really matter. But in any case I believe emilybarbie had already provided your solution as you required it.
I think use <a rel="nofollow" href=....> will be better $content = preg_replace('/<a (.*?) href=/s', '<a rel="nofollow" $1 href=', $content);
I have a similar question, I want to add rel nofollow to a part of the links from sidebar. The widgets comes from different plugins I have installed on my wordpress blog. How can I add nofollow to that links? Thanks!