【问题标题】:Wordpress - Custom Menu on Post pagesWordpress - 帖子页面上的自定义菜单
【发布时间】:2014-08-07 14:33:54
【问题描述】:

我想在“发布”页面上加载特定菜单(存在于 Wordpress 菜单中)。

这是我当前的代码(functions.php):

add_action('get_header', 'replace_post_menu');
function replace_post_menu() {
    if (is_singular('post')) {
        wp_nav_menu( array('menu' => 'New Menu' ));
    }
}

问题是菜单加载在最顶部(在我当前的菜单上方)。我正在使用主题“Avada”(最新版本)。

你能帮我吗?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    如果您想在帖子中加载特定菜单并为所有其他页面加载通用菜单,请执行以下操作。

    1. Replace the below code with your code in header.php.
    
    <?php
        if (! is_singular('post')) {
            wp_nav_menu( array('menu' => '{enter the name of your common menu here}' ));
        }
    ?>
    
    2. Keep your existing code in functions.php.
    

    【讨论】:

      猜你喜欢
      • 2014-05-30
      • 2013-10-10
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      相关资源
      最近更新 更多