douxin8610 2019-01-28 01:50
浏览 74
已采纳

PHP - 仅在主页上隐藏元素 - WordPress站点

In my footer.php file, I have this bit of code towards the end of the file:

<?php wp_footer(); ?> 

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

</div>
</body>

As you can see, I've created a "website by" link, which links to another website when clicked on.

But I don't want this text, or the div that contains it, to appear at all on the home page of the site:

https://thehamburgercollection.com/

I've checked other stackoverflow articles that suggest doing so with JQuery, which I've added to my scripts.js file:

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

And I've also tried hiding the div on the home page with CSS that was suggested here:

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

But unfortunately neither of these methods have worked. I've declared my class as website-by in the footer.php file, and have added the JQuery that should target that class in the scripts.js file, and have also added the suggested CSS. Any idea why either the JQuery or CSS code isn't working?

This is a WordPress website and a custom there. Any help / suggestions / education is appreciated!

  • 写回答

1条回答 默认 最新

  • dongre6073 2019-01-28 01:59
    关注

    I'm not a WordPress guru, but have you tried doing an if condition in the footer.php? if I got your question right, you need the .website-by to not appear elsewhere but the home page. Maybe something like

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况