我希望在WordPress站点上的每一篇文章中的内容区域中将匹配文本替换为html链接。
我是通过JavaScript实现的,如下所示。
jQuery(document).ready(function(){
var selector = `article p` ;
for (i = 0; i < document.querySelectorAll( selector ).length; i++){
if ( document.querySelectorAll( selector )[i].innerText.match(/(vpn|VPN)/) !== null ){
var term = document.querySelectorAll( selector )[i].innerText.match(/(vpn|VPN)/)[1]
document.querySelectorAll( selector )[i].innerHTML = document.querySelectorAll( selector )[i].innerHTML.replace( term ,`<a href="https://yuis-programming.com/vpn">${term}</a>`)
break
}
}
});
如您所见,将纯文本替换为p
标记,用于超链接。
所以这是我的问题。这样的JavaScript对SEO有效吗?
发布于 2020-01-20 14:41:45
谷歌看不到一些JavaScript链接,所以你需要小心。
<a href=”/good-link”>Will be crawled</a>
这是一个正常的href链接,将由谷歌爬行。
<span onclick=”changePage(‘bad-link’)”>Not crawled</span>
谷歌不会抓取这个链接,因为它不是一个锚。
<a onclick=”changePage(‘bad-link’)”>Not crawled</a>
此链接位于锚点中,但它不使用href属性。这就是为什么谷歌不会抓取它。
<a href=”/good-link” onclick=”changePage(‘good-link’)”>Will be crawled</a>
这个链接将被Google爬行,因为它是一个带有href属性的锚。
https://webmasters.stackexchange.com/questions/127186
复制相似问题