簡體   English   中英

WordPress-帖子頁面上的自定義菜單

[英]Wordpress - Custom Menu on Post pages

我想在“發布”頁面上加載特定菜單(存在於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”(最新版本)。

你可以幫幫我嗎?

如果要在帖子中加載特定菜單,而在所有其他頁面中加載公共菜單,請執行以下操作。

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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM