DWMeso Posted November 12, 2007 Share Posted November 12, 2007 I've been trying to figure out a way to make this work with Wordpress all day and I cant figure it out for anything. Basically what I'm trying to do is replace < a href="#" with < a rel="nofollow" href="#" but only for external links... anyone know how I could get this to work? I'm not skilled enough to create the script from scratch and I'm having trouble finding any answers What i'm trying to do: <?php if ( blah blah ) { PHP STR REPLACE CODE HERE } ?> I know there are wordpress plugins to make all external links nofollow, but that's not what i'm trying to do. I only need links to be nofollow if they fall into the IF.. it doesn't have to be an str replace code.. anything that does the job will work Any help will be very appreciated Quote Link to comment Share on other sites More sharing options...
bri0987 Posted November 13, 2007 Share Posted November 13, 2007 String replace works with Strings. <?php // Provides: <body text='black'> $bodytag = str_replace("%body%", "black", "<body text='%body%'>"); // Provides: Hll Wrld f PHP $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U"); $onlyconsonants = str_replace($vowels, "", "Hello World of PHP"); // Provides: You should eat pizza, beer, and ice cream every day $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = array("fruits", "vegetables", "fiber"); $yummy = array("pizza", "beer", "ice cream"); $newphrase = str_replace($healthy, $yummy, $phrase); // Use of the count parameter is available as of PHP 5.0.0 $str = str_replace("ll", "", "good golly miss molly!", $count); echo $count; // 2 // Order of replacement $str = "Line 1\nLine 2\rLine 3\r\nLine 4\n"; $order = array("\r\n", "\n", "\r"); $replace = '<br />'; // Processes \r\n's first so they aren't converted twice. $newstr = str_replace($order, $replace, $str); // Outputs: apearpearle pear $letters = array('a', 'p'); $fruit = array('apple', 'pear'); $text = 'a p'; $output = str_replace($letters, $fruit, $text); echo $output; ?> If you need to change things actively on a page as it loads you can try to use JavaScript Quote Link to comment Share on other sites More sharing options...
DWMeso Posted November 13, 2007 Author Share Posted November 13, 2007 I don't just need to replace a string though... there are plenty of topics covering how to do that. As i said, i need to replace a string in external links only, not every link on the page.. I still can't find any resources on how to do this... The script needs to check if the link is internal (pointed to a page within the website) or external, pointing to a different domain.. once it knows if it's internal or external, it should replace the string only on external links... Let me know if I'm not making sense and I can try and explain it better. Thanks for trying to help Quote Link to comment Share on other sites More sharing options...
DWMeso Posted November 13, 2007 Author Share Posted November 13, 2007 got it working myself after trying for nearly 8 hours thanks to anyone who tried to help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.