Поддержка Проблемы и решения Вставить поиск в меню?

  • Нашел такое решение:

    Добавьте в functions.php следующий хук:

    add_filter( 'wp_nav_menu_items', 'add_search_box', 10 , 2);
    function add_search_box ( $items, $args ) {
      if( 'menu-index' === $args -> theme_location )
        $items .= '<li class="custom-func-li-last">' . get_search_form(false) . '</li>';
      return $items;
    }

    стоит обратить внимание на menu-index, это название Вашего меню к которому будет добавлен элемент, получить его можно так же из файла functions.php:

    register_nav_menus( array(
      'menu-index' => 'Главное меню',
    ));

    Я попробовал у меня не получилось (Тема tempera)
    1. Куда конкретно вставлять эти коды?
    2. Имеет ли значение последовательность этих кодов?
    3. Нужно ли что то в коде менять?
    4. Как вставить что то другое, скажем выпадающие рубрики?

    Мой functions.php

    <?php
    /*
     * Functions file
     * Calls all other required files
     * PLEASE DO NOT EDIT THIS FILE IN ANY WAY
     *
     * @package tempera
     */
    
    // variable for theme version
    define ('_CRYOUT_THEME_NAME','tempera');
    define ('TEMPERA_VERSION','1.3.3');
    
    require_once(dirname(__FILE__) . "/admin/main.php"); // Load necessary admin files
    
    //Loading include files
    require_once(dirname(__FILE__) . "/includes/theme-setup.php");     // Setup and init theme
    require_once(dirname(__FILE__) . "/includes/theme-styles.php");    // Register and enqeue css styles and scripts
    require_once(dirname(__FILE__) . "/includes/theme-loop.php");      // Loop functions
    require_once(dirname(__FILE__) . "/includes/theme-meta.php");      // Meta functions
    require_once(dirname(__FILE__) . "/includes/theme-frontpage.php"); // Frontpage styling
    require_once(dirname(__FILE__) . "/includes/theme-comments.php");  // Comment functions
    require_once(dirname(__FILE__) . "/includes/theme-functions.php"); // Misc functions
    require_once(dirname(__FILE__) . "/includes/theme-hooks.php");     // Hooks
    require_once(dirname(__FILE__) . "/includes/widgets.php");     // Hooks
    require_once(dirname(__FILE__) . "/includes/ajax.php");     // Hooks
  • Тема «Вставить поиск в меню?» закрыта для новых ответов.