doure8758 2016-11-23 06:25
浏览 117
已采纳

在WordPress网站的特定页面上隐藏汉堡菜单

TheHamburgerCollection.com

My hamburger menu is working correctly on all other pages - I just don't want it to display on the home page, where it's currently visible at 768px and below.

footer.php is where the menu is located:

<div class="mobile-nav">
    <div class="menu-btn" id="menu-btn">
        <div></div>
        <span></span>
        <span></span>
        <span></span>
    </div>

    <div class="responsive-menu">
    <?php
        if ( ! is_front_page() && ! is_home() ) {
        wp_nav_menu();  
        } 
    ?>
    </div>
</div>

You can see that I've told it not to display the nav menu on the front page (which is also the home page), and it's doing this correctly - but how do I do the same thing to the hamburger menu?

I followed the instructions in this tutorial to create my hamburger menu. If I try to copy the PHP if statement that's telling the browser to display the Nav Menu on all other pages except for the Front Page / Home Page and then paste it just before the div with class and id "menu-btn", I get a syntax error:

<div class="mobile-nav">
    <?php if ( ! is_front_page() && ! is_home() ) {
        <div class="menu-btn" id="menu-btn">
            <div></div>
            <span></span>
            <span></span>
            <span></span>
        </div>
    } 
    ?>

    <div class="responsive-menu">
    <?php
        if ( ! is_front_page() && ! is_home() ) {
        wp_nav_menu();  
    } 
    ?>
    </div>
</div>

I'm not sure if there's a way to hide the hamburger menu on a specific page with CSS, or, if I do need to use PHP or JS, where should I place the function / what function should I use?

Thank you!

  • 写回答

3条回答 默认 最新

  • dongpo5264 2016-11-23 06:32
    关注

    You must close php code section before you print HTML code.

    <div class="mobile-nav">
        <?php if ( ! is_front_page() && ! is_home() ) : ?>
            <div class="menu-btn" id="menu-btn">
                <div></div>
                <span></span>
                <span></span>
                <span></span>
            </div>
        <?php endif; ?> 
    
        <div class="responsive-menu">
        <?php
            if ( ! is_front_page() && ! is_home() ) {
            wp_nav_menu();  
        } 
        ?>
        </div>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件
  • ¥150 求 《小魔指》街机游戏机整合模拟软件
  • ¥20 你好,我想问下easyExcel下拉多选,或者复选框可以实现吗
  • ¥20 双非跨考工科哪个专业和方向就业前景好?