PHP-仅在首页上隐藏元素-WordPress网站

时间:2019-01-28 01:50:58

标签: php jquery html wordpress wordpress-theming

在我的footer.php文件中,我在文件末尾有以下代码:

<?php wp_footer(); ?> 

<div class="website-by">
<br>
Website by <a href="https://gatewaywebdesign.com/" target="blank">Gateway Web Design</a>
</div>

</div>
</body>

如您所见,我创建了一个“网站依据”链接,单击该链接可以链接到另一个网站。

但是我不希望此文本或包含该文本的div完全出现在网站的主页上:

https://thehamburgercollection.com/

我已经查看了其他建议使用JQuery进行操作的stackoverflow文章,这些文章已添加到​​我的scripts.js文件中:

//hide link on the home page
document.ready(function() {
    if (window.location.href.indexOf('https://thehamburgercollection.com/')) {
      //Hide the element.
      jQuery('.website-by').hide();
    }
  });

我还尝试使用suggested here的CSS将div隐藏在主页上:

.home .website-by {
    display: none;
}

但是不幸的是,这些方法都没有起作用。我在website-by文件中将类声明为footer.php,并在scripts.js文件中添加了应以该类为目标的JQuery,并添加了建议的CSS。知道为什么JQuery或CSS代码不起作用吗?

这是一个WordPress网站和一个自定义网站。任何帮助/建议/教育表示赞赏!

1 个答案:

答案 0 :(得分:4)

我不是WordPress专家,但是您是否尝试过在if中执行footer.php条件?如果我的问题正确无误,则您需要.website-by才能显示在首页以外的其他位置。也许像

<?php wp_footer(); ?> 

<?php if (!is_home()): ?>
    <div class="website-by">
    <br>
    Website by <a href="https://gatewaywebdesign.com/" target="blank">Gateway Web Design</a>
    </div>
<?php endif; ?>

</div>
</body>
相关问题