[Support request] Which hook if I use “Use custom navigation as header”

Home Forums Support [Support request] Which hook if I use “Use custom navigation as header”

Home Forums Support Which hook if I use “Use custom navigation as header”

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1547466
    Alessio Angeloro

    Hi,

    I’m trying to put the dropdown of the categories in the first navigation, but I don’t understand which hook to use, if I use “generate_menu_bar_items” the pages and the menu are broken.

    I use this code

    function city_dropdown() { ?>
    
    <select>
        <?php
           $cities_terms = get_terms('city', array('hide_empty' => '0'));      
           foreach ( $cities_terms as $city_term ):  
              echo '<option value="'.$city_term->name.'">'.$city_term->name.'</option>';   
           endforeach;
    } ?>
    
    </select> 
    <?php
    
    add_action('generate_menu_bar_items','city_dropdown');

    Thanks.

    #1547904
    Elvin
    Staff
    Customer Support

    Hi,

    Let’s check a few things first:

    To be able to use generate_menu_bar_items, please refer to the video included in this brief documentation.
    https://docs.generatepress.com/article/generate_menu_bar_items/

    As for the code:

    Can you do a var_dump($cities_terms); of this code? To see if it works.

    $cities_terms = get_terms('city', array('hide_empty' => '0'));

    If it returns nothing, perhaps replacing it with this would work:

    $cities_terms = get_terms(array(
        'taxonomy' => 'your taxonomy name',
        'hide_empty' => false
    ));

    Reference: https://developer.wordpress.org/reference/functions/get_terms/

    #1548441
    Alessio Angeloro

    array(2) { [0]=> object(WP_Term)#17672 (10) { ["term_id"]=> int(124) ["name"]=> string(6) "Milano" ["slug"]=> string(6) "milano" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(124) ["taxonomy"]=> string(4) "city" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(0) ["filter"]=> string(3) "raw" } [1]=> object(WP_Term)#17676 (10) { ["term_id"]=> int(122) ["name"]=> string(4) "Roma" ["slug"]=> string(4) "roma" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(122) ["taxonomy"]=> string(4) "city" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(1) ["filter"]=> string(3) "raw" } } array(2) { [0]=> object(WP_Term)#17672 (10) { ["term_id"]=> int(124) ["name"]=> string(6) "Milano" ["slug"]=> string(6) "milano" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(124) ["taxonomy"]=> string(4) "city" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(0) ["filter"]=> string(3) "raw" } [1]=> object(WP_Term)#17676 (10) { ["term_id"]=> int(122) ["name"]=> string(4) "Roma" ["slug"]=> string(4) "roma" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(122) ["taxonomy"]=> string(4) "city" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(1) ["filter"]=> string(3) "raw" } }

    The code works, it returns a select with the values, the problem is that I don’t know which hook to use to put the select in the menu; considering that I have this option enabled : [url=https://postimg.cc/hz1MwkSh][img]https://i.postimg.cc/hz1MwkSh/Schermata-2020-11-26-alle-07-33-35.png[/img][/url]

    #1549505
    David
    Staff
    Customer Support

    Hi there,

    when you say the pages and menu are broken – any chance i can see that on your site ?

    #1549531
    Alessio Angeloro

    Yes, i sent you the access in private information.

    Thanks

    #1550550
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Any chance you can un-comment the code? I’m not overly comfortable breaking your site if you’re not around to fix it.

    When you say “breaking”, what do you mean exactly? Are you getting a specific error?

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.