如何在 WordPress 上仅排除空页面被 Google 索引

我已经在 WordPress 上创建了超过 10k 的页面,为了避免 Google 因内容稀薄而受到 Panda 惩罚,我所做的是将 JavaScript 代码放在 Loop-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 插件


慕慕森
浏览 73回答 1
1回答

当年话下

元标记需要进行硬编码才能发挥作用。如果您想动态创建元标记,则需要在服务器端进行。使用 PHP:if(!pageHasContent){&nbsp; echo "<meta name='robots' content='noindex, nofollow' />";&nbsp; echo "<meta name='googlebot' content='noindex' />";}
打开App,查看更多内容
随时随地看视频慕课网APP