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条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮