如何仅在 WordPress 的 Google 中排除空页面

How to exclude empty page only from being indexed in Google on WordPress

我已经在 WordPress 上创建了超过 10k 个页面,为了避免 Google 因内容稀少而受到 Panda 惩罚,我所做的是将 JavaScript 代码放在循环中-page.php 并检查页面是否没有内容,并添加元标记以禁止抓取页面,但它并非一直有效。这是我添加的代码。

<?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>

你能给我一个正确执行此操作的想法吗?当 Google 抓取页面时,我的 JavaScript 似乎不会 运行 顺便说一句,我正在使用 SEO Ultimate 插件

元标记需要进行硬编码才能发挥作用。如果您想动态创建元标记,则需要在服务器端进行。随着 PHP:

if(!pageHasContent){
  echo "<meta name='robots' content='noindex, nofollow' />";
  echo "<meta name='googlebot' content='noindex' />";
}