1. 程式人生 > >WordPress技巧:為連結的XFN關係增加nofollow屬性

WordPress技巧:為連結的XFN關係增加nofollow屬性

今天查詢站點的友鏈情況的時候發現“我的推薦”欄目下的連結並沒有加上nofollow屬性,該欄目主要存放的是一些有價值的部落格,屬於tiandi發起的單向友鏈,所以可以加上nofollow屬性以免蜘蛛爬行出去。

我們來看下預設的連結關係是沒有辦法直接輸入內容的,只能通過下面的選項來選擇,但是所有的選項都沒有nofollow屬性,所以我們需要小小的修改一下,使得這裡可以選擇nofollow專案。

xfn

修改方法也很簡單,xfn是在/wp-admin/meta-box.php裡定義的。開啟該檔案,在836行左右找到類似以下程式碼:

<tr>
	<th scope="row"><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('identity') ?></th>
	<td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('identity') ?></span></legend>
	<label for="me">
	<input type="checkbox" name="identity" value="me" id="me" <?php xfn_check('identity', 'me'); ?> />
	<?php _e('another web address of mine') ?></label>
	</fieldset></td>
</tr>

在下面新增以下程式碼即可。

<tr>
	<th scope="row">Nofollow</th>
	<td><fieldset><legend class="screen-reader-text"><span>nofollow</span></legend>
	<label for="nofollow">
	<input class="valinp" type="checkbox" name="nofollow" value="nofollow" id="nofollow" <?php xfn_check('nofollow', 'nofollow'); ?> />
	nofollow</label>
	</fieldset></td>
</tr>

好了,大功告成,看一下結果是否如下圖所示這樣了。

addnofollow

文章評分1次,平均分5.0