Managing Outbound Linking
I had my friend, Chuck Reynolds, come to me recently with a problem: He had a team of writers working on one of his sites. They were intelligent, well read, and were very diligent about citing where they got information from. Unfortunately, this meant a lot of outbound links to often untrusted sites, and he was leaking link juice like an old car leaks oil. However, this site was part of a network of sites that he did occasionally want to pass to link juice to. WHAT A CLUSTER!
So, we came up with the solution that every link needed to be automatically nofollow unless it was on a whitelist. This would have been a big job to write in a plugin, but luckily there was already plugin available to modify. NoLip allows you to automatically convert all your posts’ links to nofollow after a certain amount of time. This way you can still be nice to those who you’re linking to, but ultimately, you can stop the bleeding. I modified this plugin to make use of a “whitelist”. Any domain that appears in the whitelist will NOT receive the nofollow tag. Simply add a whitelist.txt in the same directory as this plugin and add domains separated by line breaks WITHOUT www. Example:
http://josh.com http://google.com
The plugin works by taking the post and parsing out all the links and adding nofollow. I simply jump in with a function called is_on_whitelist and remove the links from that list we want to preserve. Regex is used liberally here btw. Line 155 is my function, Line 108 is where I weed out the unwanted links. Here’s the modified plugin code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | <?php /* Plugin Name: NoLIP: Nofollow Links in Posts Reborn! Plugin URI: http://www.theresabloginmysoup.com/wordpress-plugins/nolip/ Description: Adds the rel="nofollow" to links in posts within a selected category. Useful for sponsored posts. Author: Patrick Curl Version: 2.0 Author URI: http://www.theresabloginmysoup.com/ */ /* Copyright (C) 2009 Patrick Curl @ TheresABlogInMySoup.com Originally developed by: Ibnu Asad @ TheMiak.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ if(!function_exists('make_nofollow_links')) { function make_nofollow_links($content) { global $post; if(isset($post->ID) && is_numeric($post->ID)) { $post2cats = wp_get_post_categories($post->ID); //getting global settings $default_older = get_option('global_nofollow_settings'); $default_older = trim($default_older) == '' || !is_numeric($default_older)?-1:$default_older; // $added_no_follow_cats = unserialize(get_option('nofollow_cats')); $added_no_follow_cats = get_option('nofollow_cats'); $added_no_follow_cats = !is_array($added_no_follow_cats)?unserialize($added_no_follow_cats):$added_no_follow_cats; $added_no_follow_cats = !is_array($added_no_follow_cats)?array():$added_no_follow_cats; $filter_categories = array_intersect($post2cats,array_keys($added_no_follow_cats)); //getting the post date $post_date_time = explode(" ",$post->post_date); $post_dateonly = explode("-",$post_date_time[0]); $post_timeonly = explode(":",$post_date_time[1]); $timediff = time() - mktime($post_timeonly[0],$post_timeonly[1],$post_timeonly[2],$post_dateonly[1],$post_dateonly[2],$post_dateonly[0]); $totalDaysNofollow = floor($timediff/(60*60*24)); if($default_older > 0) { if($totalDaysNofollow >= $cat_date) { $content = make_nofollow( $content ); } } else if(count($filter_categories) > 0) { $proceed_nofollow = true; //do filter for categories for($i=0;$i<count($filter_categories);$i++) { if(!isset($cat_date)) { $cat_date = $added_no_follow_cats[$filter_categories[$i]]['numdays']; $over_ride = $added_no_follow_cats[$filter_categories[$i]]['overrideind']; } else { if($added_no_follow_cats[$filter_categories[$i]]['numdays'] > $cat_date) { $cat_date = $added_no_follow_cats[$filter_categories[$i]]['numdays']; $over_ride = $added_no_follow_cats[$filter_categories[$i]]['overrideind']; } } } if($over_ride == 1) { if(get_post_meta($post->ID, 'nofollow4post', true) == 1 && $over_ride == 1) { $proceed_nofollow = false; } } if($proceed_nofollow == true && $totalDaysNofollow >= $cat_date) { $content = make_nofollow( $content ); } } } return $content; } } if(!function_exists('make_nofollow')) { function make_nofollow( $text ) { preg_match_all("/<a.*? href=\"(.*?)\".*?>(.*?)<\/a>/i", $text, $matches); //print_r($matches); for($i=0;$i<count($matches[0]);$i++) { if(is_on_whitelist($matches[1][$i])) { unset($matches[0][$i]); unset($matches[1][$i]); unset($matches[2][$i]); } } $matches[0] = array_merge($matches[0]); //print_r($matches[0]); //echo "SIZE IS ".count($matches[0]); for($i=0;$i<count($matches[0]);$i++) { if(!preg_match("/rel=[\"\']*nofollow[\"\']*/",$matches[0][$i])) { //echo "FOUND NO NOFOLLOW"; // $replaced = str_replace('<a ','<a rel="nofollow"',$matches[0][$i]); //$text = str_replace($matches[0][$i],$replaced,$text); preg_match_all("/<a.*? href=\"(.*?)\"(.*?)>(.*?)<\/a>/i", $matches[0][$i], $matches1); //print_r($matches1); $text = str_replace(">".$matches1[3][0]."</a>"," rel='nofollow'>".$matches1[3][0]."</a>",$text); } } return $text; } } add_action('the_content', 'make_nofollow_links'); function build_catTree($name,$cats_nofollow_array,$edit_cats,$default = null) { $categories = get_categories($cats_nofollow_array); echo '<select onchange="changeCat();" name="'.$name.'">'; foreach($categories as $key=>$val) { $selected = ''; if($default != null) { $selected = $default == $val->cat_ID?' Selected ':''; } $bold = in_array($val->cat_ID,$edit_cats)?' style="font-weight:bold"':''; echo '<option value="'.$val->cat_ID.'" '.$bold.$selected.'>'.$val->cat_name.'</option>'; } echo '</select>'; } if(!function_exists('is_on_whitelist')) { function is_on_whitelist($url) { $urls = file_get_contents("/home/burglar/public_html/wp-content/plugins/whitelist.txt"); $urls = explode("\n",$urls); foreach($urls as $whiteurl) { preg_match('/http:\/\/((.*)(.net|.com|.biz|.org|.info))/',$whiteurl,$whitedomain); //preg_match('/http:\/\/((.*)(.net|.com|.biz|.org|.info))/',$url,$testurl); if(strpos(trim($url),trim($whitedomain[1])) !== false) { //echo "$url is in $whitedomain[1]"; //die(); return(true); } } return(false); } } //================================================ //taking the admin part into action if(preg_match('/wp-admin/',$_SERVER['PHP_SELF'])) { class admin_makenofollow { function init_makenofollow() { add_action('admin_menu', array('admin_makenofollow', 'add_makenofollowoption_page')); } function add_makenofollowoption_page() //adding menu itme into option page { if ( !function_exists('get_site_option') || is_admin() ) { add_options_page(__('NoLiP'), __('NoLiP'), 7, str_replace("\\", "/", __FILE__), array('admin_makenofollow', 'display_makenofollow_settings')); } } function display_makenofollow_settings() { $makenofollow_url = $_SERVER['PHP_SELF'].'?page=NoLiP/'.basename(__FILE__); if(isset($_POST['older_than_days']) && is_numeric($_POST['older_than_days'])) { update_option('global_nofollow_settings',$_POST['older_than_days']); } $default_older = get_option('global_nofollow_settings'); $default_older = trim($default_older) == '' || !is_numeric($default_older)?-1:$default_older; if(isset($_POST['btnNofollowAction'])) { $numberofdays = trim($_POST['num_days']); $overrideindividual = isset($_POST['over_ride']) && $_POST['over_ride'] == 'ind_over'?1:0; $added_no_follow_cats = get_option('nofollow_cats'); $added_no_follow_cats = !is_array($added_no_follow_cats)?unserialize($added_no_follow_cats):$added_no_follow_cats; $added_no_follow_cats = !is_array($added_no_follow_cats)?array():$added_no_follow_cats; if($_POST['btnNofollowAction'] == 'DELETE') { foreach($added_no_follow_cats as $key=>$value) { if($_POST['nofollow_cat'] == $key) { unset($added_no_follow_cats[$key]); update_option('nofollow_cats',serialize($added_no_follow_cats)); $deleted = true; $error = "Options Deleted"; } } } if(!isset($deleted)) { if(!is_numeric($numberofdays)) { $error = "Enter Numeric Value in Number of Days field"; } $added_no_follow_cats[$_POST['nofollow_cat']]['numdays'] = $numberofdays; $added_no_follow_cats[$_POST['nofollow_cat']]['overrideind'] = $overrideindividual; update_option('nofollow_cats',serialize($added_no_follow_cats)); $error = "Options Added/Updated"; } } if(!isset($added_no_follow_cats)) { //category options if any $added_no_follow_cats = get_option('nofollow_cats'); $added_no_follow_cats = !is_array($added_no_follow_cats)?unserialize($added_no_follow_cats):$added_no_follow_cats; $added_no_follow_cats = !is_array($added_no_follow_cats)?array():$added_no_follow_cats; } if(isset($_GET['nofollow_cat'])) { $cat_nofollow = $_GET['nofollow_cat']; } $parent_cat_nofollow = isset($cat_nofollow) && !empty($cat_nofollow)?$cat_nofollow:min(get_all_category_ids()); if(isset($added_no_follow_cats[$parent_cat_nofollow])) { $nofollow_days = $added_no_follow_cats[$parent_cat_nofollow]['numdays']; $over_checked = $added_no_follow_cats[$parent_cat_nofollow]['overrideind'] == 1?"checked":""; $btnValue = "EDIT"; } else { $nofollow_days = ''; $over_checked = ""; $btnValue = "ADD"; } ?><div class="wrap"> <h2>NoLiP - Options</h2><BR /> <style type="text/css"> a.sm_button { padding:4px; display:block; padding-left:25px; background-repeat:no-repeat; background-position:5px 50%; text-decoration:none; border:none; } a.sm_button:hover { border-bottom-width:1px; } </style> <style type="text/css"> div#moremeta { float:left; width:300px; margin-right:10px; } div#advancedstuff { width:770px; } div#poststuff { margin-top:10px; } fieldset.dbx-box { margin-bottom:5px; } </style> <!--[if lt IE 7]> <style type="text/css"> div#advancedstuff { width:735px; } </style> <![endif]--> <div id="poststuff" > <div id="moremeta"> <div id="grabit" class="dbx-group" style="border:1px; border-color: #000000; border-style: dashed"> <fieldset id="sm_pnres" class="dbx-box"> <h3 class="dbx-handle">About this Plugin:</h3> <div class="dbx-content"> <a class="sm_button" href="http://www.thereseabloginmysoup.com/">Author URI</a> <a class="sm_button" href="http://www.theresabloginmysoup.com/wordpress-plugins/nolip/">Plugin Homepage</a> <a class="sm_button" href="http://www.twitter.com/">Follow me on Twitter</a> </div> </fieldset> <fieldset id="sm_smres" class="dbx-box"> <h3 class="dbx-handle">Like this Plugin? </h3> <div class="dbx-content" style="margin-left: 10px;"> If you like this plugin, please donate to our Adoption fund as a bonus you'll get your link on some huge sites!: <div id="ScratchBackWidget" align="center"> <script type="text/javascript" src="http://www.scratchback.com/widget.php?id=513385ce-5e7c-d964-f17f-f2bf06efe92f"></script> </div> <center><strong>Donate and Get YOUR Link on These Great Sites:</strong></center> <ul><li><a href="http://www.twtfollow.com">TwtFollow - Get More Twitter Followers!</a></li> <li><a href="http://www.theresabloginmysoup.com">There's a Blog in my Soup: Social Media tips for a Social World!</a></li> <li><font color="red">PLUS - EVERY WORDPRESS ADMIN AREA that has this plugin installed! </font></li></ul> </div> </fieldset> </div> </div> <div class="dbx-c-ontent-wrapper" > <div class="dbx-content"> <div align="center"> <h1>NoFollow Links in Posts - Reloaded!</h1> <table width='60%'><tr><td>This plugin will give you some control over how you use nofollow. <p>If you don't use nofollow your Google rankings will surely plummett. However there are sometimes when you need to follow links, for instance sometimes sponsored blog posts from sponsoredreviews.com requires you to give link love to their advertisers.</p> <p>Don't think no follow matters? I had a blog with a PR of 0 for 2 years, then added nofollow to EVERY LINK on the blog (except where I agreed not to for a sponsor - and my google pagerank went upto 3).</p> <p>Tip: When choosing how many days to wait, the minimum is currently set at 1 day. Setting this value to 0 will not work!</p> </td></tr></table></div><center><h1>Plugin Settings</h1></center> <form method="post" name="makenofollow" onsubmit="return check_form();"> <center> <table width="65%" style="border:thin; border-style: dashed;" > <caption style="color:#FF0000"> <?php if(isset($error)) { echo $error; } ?> </caption> <tr><td width="60%">Enable nofollow to links in posts older than<input type="text" value="<?php echo $nofollow_days; ?>" name="num_days" size="5" /> days in</td><td align="left"><?php $dropdown_options_nofollow = array('hide_empty' => 0, 'hierarchical' => 1, 'name'=>'nofollow_cat','show_count' => 0, 'orderby' => 'ID', 'selected' => $cat_nofollow); build_catTree('nofollow_cat',$dropdown_options_nofollow,array_keys($added_no_follow_cats),$parent_cat_nofollow); ?></td></tr> <tr><td>Enable individual post to override the settings<input type="checkbox" name="over_ride" value="ind_over" <?php echo $over_checked;?> /></td><td><input type="submit" value="<?php echo $btnValue;?>" name="btnNofollowAction" /> <?php if($btnValue == 'EDIT') { ?> <input type="submit" value="DELETE" name="btnNofollowAction" /> <?php } ?> </form></td></tr> <tr><td width="60%"> <form method="post" onsubmit="return checkOlderDays();" name="new_form"> Enable nofollow to links in ALL posts older than <input type="text" name="older_than_days" size="3" value="<?php echo $default_older;?>" /> days<br /><font size="2"><strong><font color="red">NOTE:</font> If you enable this setting, all the nofollow settings for individual posts and posts within categories will be ignored.</strong></font></td><td><input type="submit" value="APPLY" /> [Put -1 for no effect] </form> </td></tr></table> </center> </div></div> </div> <p> <table align="center" width="75%"> <tr><td colspan="7" align="center"><strong>Support this Plugin: Visit our Sponsors!</strong></td></tr> <tr> <td align="center"><a href="http://www.theresabloginmysoup.com/go/woothemes/"> <img src="http://www.woothemes.com/ads/woothemes-125x125-1.gif" border=0 alt="WooThemes - Premium WordPress Themes Club" width=125 height=125></a></td> <td align="center"><a href="http://thirtydealsamonth.com/a.php?a=CD10123&b=25367&d=0&l=0&o=&p=0&c=4110&s1=&s2=&s3=&s4=&s5="><img src="http://users.marketleverage.com/42/10123/25367/" alt="" border="0"></a></td> <td align="center"><a href="http://www.theresabloginmysoup.com/go/bluehostside/" target="_blank"><img src="http://www.ftjcfx.com/jd77snrflj47EE7BEA4658DDACD" alt="Host Unlimited Domains on 1 Account" border="0"/></a></td> <td align="center"><a href="http://www.theresabloginmysoup.com/go/aweber/" title="Email Marketing"><img src="http://www.aweber.com/banners/email_marketing/125x125_an.gif" alt="Email Marketing $19/Month!" style="border:none;" /></a></td> <td align="center"><a href="http://www.theresabloginmysoup.com/go/shoemoney/"><img src="http://www.theresabloginmysoup.com/shoemoneyaff.gif"></a></td> <td align="center"><a href="http://revtwt.com/index.php?id=5674"><img src="http://revtwt.com/images/TwtAd_referral.jpg"></a></td> <td align="center"><a href="http://www.tweetlater.com/86475-0-1-3.html" target="_blank"><img border="0" src="http://www.tweetlater.com/idevaffiliate/banners/tl_125_125_01.gif" width="125" height="125"></a></td> </tr> </table> </p> <br /><br /><p align="center">This plugin brought to you buy <a href="http://www.twtfollow.com">TwtFollow©2009</a> || <a href="http://www.theresabloginmysoup.com">There's a Blog in my Soup©2009</a></p> <script language="javascript"> function changeCat() { if(<?php echo $parent_cat_nofollow;?> != document.makenofollow.nofollow_cat.value) { window.location = '<?php echo $makenofollow_url;?>&nofollow_cat='+document.makenofollow.nofollow_cat.value; } } function check_form() { if(document.makenofollow.num_days.value == "") { alert("Enter Number Of Days"); document.makenofollow.num_days.focus(); return false; } else if(isNaN(document.makenofollow.num_days.value)) { alert("Enter Numeric Values Only"); document.makenofollow.num_days.focus(); return false; } else if(document.makenofollow.num_days.value <= 0) { alert("Enter Greater Than Zero"); document.makenofollow.num_days.focus(); return false; } return true; } function checkOlderDays() { if(document.new_form.older_than_days.value == "") { alert("Enter Number Of Days"); document.new_form.older_than_days.focus(); return false; } else if(isNaN(document.new_form.older_than_days.value)) { alert("Enter Numeric Values Only"); document.new_form.older_than_days.focus(); return false; } return true; } </script> <?php } function advanced_makefollow() { if (substr($GLOBALS['wp_version'], 0, 3) >= 2.5) { ?> <div id="makenofollow" class="postbox closed"> <h3>Nofollow Links in Posts - Advanced Option</h3> <div class="inside"> <div id="makenofollow"> <?php } else { ?> <div class="dbx-b-ox-wrapper"> <fieldset id="makenofollowdiv" class="dbx-box"> <div class="dbx-h-andle-wrapper"> <h3 class="dbx-handle">Nofollow Links in Posts</h3> </div> <div class="dbx-c-ontent-wrapper"> <div class="dbx-content"> <?php } ?> <input type="checkbox" name="always_dofollow" value="1" <?php if(isset($post->ID) && get_post_meta($post->ID, 'nofollow4post', true) == 1) { echo " checked"; } ?> /> Always DoFollow Links <?php if (substr($GLOBALS['wp_version'], 0, 3) == '2.5') { ?> </div></div></div> <?php } else { ?> </div> </fieldset> </div> <?php } } function nofollow2posts($id) { $post_option_nofollow = isset($_POST['always_dofollow']) && $_POST['always_dofollow'] == '1'?1:0; delete_post_meta($id, 'nofollow4post'); add_post_meta($id, 'nofollow4post', $post_option_nofollow); } } admin_makenofollow::init_makenofollow(); if (substr($GLOBALS['wp_version'], 0, 3) >= 2.5) { add_action('edit_form_advanced', array('admin_makenofollow', 'advanced_makefollow')); } else { add_action('dbx_post_advanced', array('admin_makenofollow', 'advanced_makefollow')); } add_action('edit_post', array('admin_makenofollow', 'nofollow2posts')); add_action('publish_post', array('admin_makenofollow', 'nofollow2posts')); add_action('save_post', array('admin_makenofollow', 'nofollow2posts')); } ?> |

From what I understand, even nofollow links leak link juice just no one gets it. So google still divides the PR by the number of links on the page including nofollow links but does not pass that juice on.
http://www.mattcutts.com/blog/pagerank-sculpting/
I think this is the place i read this a while back.
Here are some tests that prove otherwise: http://www.seomoz.org/blog/pagerank-sculpting-with-nofollow-still-works