我已經添加了此代碼,以我的functions.php文件:如何將搜索欄添加到wordpress的移動菜單中?
function wpgood_nav_search($items, $args) {
$items .= '<li>' . get_search_form(false) . '</li>';
return $items;
}
add_filter('wp_nav_menu_items','wpgood_nav_search', 10, 2);
我發現在這裏: adding search bar to the nav menu in wordpress
問題:這個代碼將搜索欄爲桌面和移動菜單,但我需要將搜索欄僅添加到我的移動菜單,因爲我的網站的桌面版本已在左側欄中有一個搜索窗口小部件。
我該怎麼做?請幫幫我。謝謝!
我的菜單Initializiation中的functions.php:
// Initialize navigation menus
register_nav_menus(
array(
'primary-menu' => esc_html__('Primary Menu', 'bento'),
'footer-menu' => esc_html__('Footer Menu', 'bento'),
)
);
非常感謝你的幫助!最後我決定用我的最初的代碼和編輯搜索欄的位置和樣式與CSS,因爲我在編碼:)
不工作,手機菜單變得無法點擊,我看到桌面菜單標題中的混亂:(謝謝你的回覆 –