那么如何添加 nofollow 选项呢?
方法1:直接修改源代码
以WordPress 4.5.3为例,编辑/wp-admin/includes/meta-boxes.php,在1145行添加如下代码:
- <tr>
- <thscope=“row”>nofollow</th>
- <td>
- <fieldset>
- <legendclass=“screen-reader-text”><span>nofollow</span></legend>
- <labelfor=“nofollow”><inputclass=“valinp”type=“checkbox”name=“nofollow”value=“nofollow”id=“nofollow”<?phpxfn_check(‘nofollow’);?>/>nofollow</label>
- </fieldset>
- </td>
- </tr>
然后你再添加链接时,就会在“链接关系(XFN)”列表中看到 nofollow 选项了。如图:
不太推荐修改WP源代码,因为每次更新你都要修改一遍。
方法2:使用Add-nofollow-to-XFN插件
如果你不想折腾代码,可以使用插件Add-nofollow-to-XFN实现同样效果。当然,你也可以在主题的 functions.php 添加下面的代码(来自于插件):
- /*
- PluginName:Add-nofollow-to-XFN
- PluginURI:http://www.slyar.com/blog/Add-nofollow-to-XFN
- Description:在后台链接管理的XFN关系中添加一个nofollow标签
- Author:Slyar
- Version:1.2
- AuthorURI:http://www.slyar.com/
- */
- functionadmin_xfn(){?>
- <scripttype=“text/javascript”>
- addLoadEvent(addNofollowTag);
- functionaddNofollowTag(){
- tables=document.getElementsByTagName(‘table’);
- for(i=0;i<tables.length;i++){
- if(tables[i].getAttribute(“class”)==“links-table”){
- tr=tables[i].insertRow(1);
- th=document.createElement(‘th’);
- th.setAttribute(‘scope’,’row’);
- th.appendChild(document.createTextNode(‘Follow’));
- td=document.createElement(‘td’);
- tr.appendChild(th);
- label=document.createElement(‘label’);
- input=document.createElement(‘input’);
- input.setAttribute(‘type’,’checkbox’);
- input.setAttribute(‘id’,’nofollow’);
- input.setAttribute(‘value’,’nofollow’);
- label.appendChild(input);
- label.appendChild(document.createTextNode(‘nofollow’));
- td.appendChild(label);
- tr.appendChild(td);
- input.name=‘nofollow’;
- input.className=‘valinp’;
- if(document.getElementById(‘link_rel’).value.indexOf(‘nofollow’)!=-1){
- input.setAttribute(‘checked’,’checked’);
- }
- return;
- }
- }
- }
- </script>
方法3:创建一个独立的Meta选项
仍旧可以添加到主题的 functions.php :
- /**
- *一下两个钩子是为了保证代码只在links页面显示
- *如果你想了解更多load-$pageaction的信息,访问http://codex.wordpress.org/Adding_Administration_Menus#Page_Hook_Suffix
- */
- add_action(‘load-link.php’,‘sola_blogroll_nofollow’);
- add_action(‘load-link-add.php’,‘sola_blogroll_nofollow’);
- functionsola_blogroll_nofollow(){
- //通过actionadd_meta_boxes创建我们需要的MetaBox
- add_action(‘add_meta_boxes’,‘sola_blogroll_add_meta_box’,1,1);
- //通过filterpre_link_rel将数据保存
- add_filter(‘pre_link_rel’,‘sola_blogroll_save_meta_box’,10,1);
- }
- //创建NofollowMetaBox
- functionsola_blogroll_add_meta_box(){
- //翻译成中文就是,创建一个名叫BlogrollNofollow的MetaBox,放在link页面的右侧边栏,MetaBox的结构
- //由函数sola_blogroll_inner_meta_box产生
- add_meta_box(‘sola_blogroll_nofollow_div’,__(‘BlogrollNofollow’),‘sola_blogroll_inner_meta_box’,‘link’,‘side’);
- }
- //输出MetaBox的HTML结构
- functionsola_blogroll_inner_meta_box($post){
- $bookmark=get_bookmark($post->ID,‘ARRAY_A’);
- if(strpos($bookmark[‘link_rel’],‘nofollow’)!==FALSE)
- $checked=‘checked=“checked”‘;
- else
- $checked=”;
- ?>
- <labelfor=“sola_blogroll_nofollow_checkbox”><?phpecho__(‘Nofollowthislink?’);?></label>
- <inputvalue=“1”id=“sola_blogroll_nofollow_checkbox”name=“sola_blogroll_nofollow_checkbox”<?phpecho$disabled;?>type=“checkbox”<?phpecho$checked;?>/><?phpecho$message;?>
- <?php
- }
效果如下图: