我已經(jīng)在 WordPress 上創(chuàng)建了超過 10k 的頁面,為了避免 Google 因內(nèi)容稀薄而受到 Panda 懲罰,我所做的是將 JavaScript 代碼放在 Loop-page.php 上,并檢查頁面是否沒有內(nèi)容并添加了元數(shù)據(jù)禁止抓取頁面的標(biāo)簽,但它并不總是有效。這是我添加的代碼。<?php if($post->post_content=="") { ?><p>We are still updating our website with contents. Please check back next time.</p><script> (function(){ var meta = document.createElement("meta"); meta.setAttribute("name", "robots"); meta.setAttribute("content", "noindex, nofollow"); document.head.appendChild(meta); var meta2 = document.createElement("meta"); meta2.setAttribute("name", "googlebot"); meta2.setAttribute("content", "noindex"); document.head.appendChild(meta2); })()</script>您能給我一個(gè)正確執(zhí)行此操作的想法嗎?當(dāng) Google 抓取頁面時(shí),我的 JavaScript 似乎無法運(yùn)行,順便說一句,我正在使用 SEO Ultimate 插件
1 回答

當(dāng)年話下
TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
元標(biāo)記需要進(jìn)行硬編碼才能發(fā)揮作用。如果您想動(dòng)態(tài)創(chuàng)建元標(biāo)記,則需要在服務(wù)器端進(jìn)行。使用 PHP:
if(!pageHasContent){
echo "<meta name='robots' content='noindex, nofollow' />";
echo "<meta name='googlebot' content='noindex' />";
}
- 1 回答
- 0 關(guān)注
- 141 瀏覽
添加回答
舉報(bào)
0/150
提交
取消