admin管理员组文章数量:1122832
I got all my website with a lot of internal cloaked links with a nofollow attribute.
I need a function or filter to add inside functions.php
that removes the nofollow
attribute when the permalink contains a specific word es "/link/pluto"
. Could you help me?
Thanks for your support. Gp
I got all my website with a lot of internal cloaked links with a nofollow attribute.
I need a function or filter to add inside functions.php
that removes the nofollow
attribute when the permalink contains a specific word es "/link/pluto"
. Could you help me?
Thanks for your support. Gp
Share Improve this question edited Aug 24, 2019 at 8:13 nmr 4,5212 gold badges17 silver badges25 bronze badges asked Aug 23, 2019 at 14:31 GmacGmac 434 bronze badges2 Answers
Reset to default 1I wrote the following code to address ADDING tag attributes, but here is a version to help you locate, and remove nofollow
:
add_filter( 'the_content', 'ex1_the_content_filter' );
function ex1_the_content_filter($content) {
// finds all links in your content with a nofollow
preg_match_all('/\<a .*?"nofollow".*?a>/',$content,$matches, PREG_SET_ORDER);
// loop through all matches
foreach($matches as $m){
// potential link to be replaced...
$toReplace = $m[0];
// You can add whatever additional "IF" conditions you require to this one
if (preg_match('/.*?\/pluto.*?/',$toReplace)){
// removes rel="nofollow" from the current link
$replacement = preg_replace('/(<a.*?)(rel="nofollow")(.*?a\>)/','$1$3',$toReplace);
// replaces the current link with the $replacement string
$content = str_ireplace($toReplace,$replacement,$content);
}
}
return $content;
}
you are my hero. I solved my issue with internal links with your code. I had to modify it because i got many different rel inside my code rel="nofollow nooopener" and rel="nooopener nofollow" so i modify with this:
add_filter( 'the_content', 'ex1_the_content_filter' );
function ex1_the_content_filter($content) {
// finds all links in your content with a nofollow
preg_match_all('/\<a .*?nofollow.*?a>/',$content,$matches, PREG_SET_ORDER);
// loop through all matches
foreach($matches as $m){
// potential link to be replaced...
$toReplace = $m[0];
// You can add whatever additional "IF" conditions you require to this one
if (preg_match('/.*?\/link.*?/',$toReplace)){
// removes rel="nofollow" from the current link
$replacement = preg_replace('/(<a.*?)(nofollow )(.*?a\>)/','$1$3',$toReplace);
// replaces the current link with the $replacement string
$content = str_ireplace($toReplace,$replacement,$content);
}
}
return $content;
}
本文标签: Remove nofollow from specific internal links
版权声明:本文标题:Remove nofollow from specific internal links 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295736a1929634.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论