Add WordPress friendly links with optional nofollow option

888u

Last update at :2024-07-09,Edit by888u

Have we seen that some webmasters add the nofollow tag to the target website after exchanging links? Friends who understand SEO should know the meaning of this tag. Since the other party has added nofollow to your friendly link, we should also add it to him. How do we add this?

//WordPress friend links support setting the nofollow attribute laobuluo.com
add_action('load-link.php', 'fanly_blogroll_nofollow');
add_action('load-link-add.php', 'fanly_blogroll_nofollow');
function fanly_blogroll_nofollow(){
add_action('add_meta_boxes', 'fanly_blogroll_add_meta_box', 1, 1);
add_filter('pre_link_rel', 'fanly_blogroll_save_meta_box', 10, 1);
}
function fanly_blogroll_add_meta_box(){
add_meta_box('fanly_blogroll_nofollow_div', 'Nofollow', 'fanly_blogroll_inner_meta_box', 'link', 'side');
}
function fanly_blogroll_inner_meta_box($post){
 $bookmark = get_bookmark($post->ID, 'ARRAY_A');
if (strpos($bookmark['link_rel'], 'nofollow') !== false) { $checked = ' checked="checked"';} else { $checked = ''; }
 echo '';
}
function fanly_blogroll_save_meta_box($link_rel){
 $rel = trim(str_replace('nofollow', '', $link_rel));
if ($_POST['fanly_blogroll_nofollow_checkbox']) { $rel .= ' nofollow'; }
return trim($rel);
}

Add the above code to the current theme's functions.php file. Then when we go to the friendly link adding page, we can see that Nofollow is optional.

Here we can see that when adding a friendly link, we see an additional label option on the right.

Recommended site search: How to register a website, Hong Kong cloud hosting, registration-free space in mainland China, domain name registration website, dynamic IP server, server hosting, purchase domain name, free ftp space, Guangdong hosting hosting space,

Add WordPress friendly links with optional nofollow option

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码