我已經(jīng)在 WordPress 上創(chuàng)建了超過 10k 的頁面,為了避免 Google 因內(nèi)容稀薄而受到 Panda 懲罰,我所做的是將 JavaScript 代碼放在 Loop-page.php 上,并檢查頁面是否沒有內(nèi)容并添加了元數(shù)據(jù)禁止抓取頁面的標簽,但它并不總是有效。這是我添加的代碼。<?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>您能給我一個正確執(zhí)行此操作的想法嗎?當 Google 抓取頁面時,我的 JavaScript 似乎無法運行,順便說一句,我正在使用 SEO Ultimate 插件
1 回答

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