admin管理员组文章数量:1122832
My footer social icons widget includes a nofollow attribute in links to my social media pages. I cannot find an option to turn this off. How might I remove this attribute either with a setting or functions.php code?
My footer social icons widget includes a nofollow attribute in links to my social media pages. I cannot find an option to turn this off. How might I remove this attribute either with a setting or functions.php code?
Share Improve this question asked Jan 14, 2023 at 16:47 user16421user16421 1 3- 1 Where did you get the widget from? It's not possible to answer this without seeing the code for the widget or knowing where it came from. If this widget is provided by a 3rd party theme then you'll need to ask their support routes as 3rd party product/service support is offtopic here – Tom J Nowell ♦ Commented Jan 14, 2023 at 17:00
- @TomJNowell it's an inbuilt Wordpress widget, hence why I'm asking here: wordpress.com/support/wordpress-editor/blocks/… – user16421 Commented Jan 15, 2023 at 6:59
- that's not a widget, that's a block – Tom J Nowell ♦ Commented Jan 16, 2023 at 10:21
2 Answers
Reset to default 0As of 6.1.1, I have discovered you can achieve this by disabling the option to open each social link in a new tab. Imagine this will change in a future WP update.
You should really put this in an external file and enqueue it properly in your website footer using the WordPress default enqueue methods, either in your custom theme or from inside a custom plugin, which you can research, but to test it quickly you can drop this in at the very bottom of your theme footer.
The code should remove the nofollow
value while keeping anything else in the rel
attribute, noting that because they will be opening in a new tab/window, they must keep noopener
and/or noreferrer
to avoid security issues:
<script>
var links = document.querySelectorAll(".social-links a[rel='nofollow']");
links.forEach(function(link) {
var relAttr = link.getAttribute("rel");
var newRelAttr = relAttr.replace("nofollow ", "").replace("nofollow", "");
link.setAttribute("rel", newRelAttr);
});
</script>
Also note that you will have to change the .social-links
class to whatever the class name is of the WordPress social links block.
As a side note, Google's John Mueller recently tipped that you should use rel="me"
for social profile links, despite other sources saying it died out years ago, so it may be worth putting that in the replace above instead of an empty string.
本文标签: Remove nofollow attribute from social widget links
版权声明:本文标题:Remove nofollow attribute from social widget links 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283492a1926986.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论