URLs are not being displayed properly in custom menu

Viewing 15 posts - 1 through 15 (of 17 total)
  • #20103
    ehd
    Participant

    I have created a dynamic sidebar that will hold a custom menu for some pages to have alternate navigation. I have created a menu to hold the pages that I want to include in this custom menu. I have changed the default sidebar for one page to set the Primary Sidebar to my new dynamic sidebar. Saved changes, page appears to have taken changes. When I view the page, I see my menu, but the URLS do not go to correct pages. They take the page I am on and append role= to the URL. Not sure how to correct this issue…

    • This topic was modified 9 years, 10 months ago by ehd.
    #20134
    Daniel Tara
    Keymaster

    There is currently a bug when adding navigation menus to sidebars. It will be fixed in the next version that will be released shortly.

    #20230
    SharkBait
    Participant

    Hi,

    This bug does not yet seem to be fixed in the latest version (.15). Or am I missing something?

    Please help.

    By the way, this is an excellent theme – thank you!!

    #20252
    Daniel Tara
    Keymaster

    This is a complicated bug as this functionality is dependent on some WordPress hooks and fixing it in one place breaks it in the other. Please have patience, we will find a solution eventually.

    #20345
    simoami
    Participant

    I hit the same problem. Upon debugging, the culprit is in core/functions/navigation.php (line 29)

    
    function enlightenment_nav_menu_container_extra_atts( $nav_menu, $args ) {
            $atts = apply_filters( 'enlightenment_nav_menu_container_extra_atts', ' role="navigation"' );
    
            $nav_menu = str_replace(
                    $args->container_class . '"',
                    $args->container_class . '"' . enlightenment_extra_atts( $atts ),
                    $nav_menu
            );
            return $nav_menu;
    }
    

    The condition occurs when $args->container_class is blank. so the replace logic becomes unprecise as it replaces the first double-quote (“) character it encounters as opposed to the last closing double quote.

    For example, given:

    
    <div class="menu">
    

    when $args->container_class is blank, the search phrase is ” and the replacement is ” role=”navigation”

    after the replace operation, the string becomes:

    
    <div class=" role="navigation"menu">
    

    and as you can see all of the tag attributes are swallowed.

    My Recommendation:

    Since $args->container_class is not a reliable source, it would be more efficient to use regular expressions to replace the class attribute’s closing quote.

    #20346
    simoami
    Participant

    Here’s my fix:

    In themes/enlightenment/core/functions/navigation.php (line 29), replace the following block:

    
    $nav_menu = str_replace(
                    $args->container_class . '"',
                    $args->container_class . '"' . enlightenment_extra_atts( $atts ),
                    $nav_menu
            );
    

    with:

    
    $nav_menu = preg_replace('/(class=\"[^"]*)/i', '\1"' . enlightenment_extra_atts( $atts ), $nav_menu);
    

    The final function should look like this:

    
    function enlightenment_nav_menu_container_extra_atts( $nav_menu, $args ) {
            $atts = apply_filters( 'enlightenment_nav_menu_container_extra_atts', ' role="navigation"' );
    
            $nav_menu = preg_replace('/(class=\"[^"]*)/i', '\1"' . enlightenment_extra_atts( $atts ), $nav_menu);
            
            return $nav_menu;
    }
    

    Voila!

    #20382
    Daniel Tara
    Keymaster

    You’re good. Thank your for this contribution, much appreciated.

    #20416
    simoami
    Participant

    You’re welcome! Thanks for this great theme.

    #20620
    simoami
    Participant

    Sorry, I got the previous code slightly messed up. The proper line with the regular expression should be:

    preg_replace('/(class=\"[^"]*\")/i', '\1' . enlightenment_extra_atts( $atts ), $nav_menu);
    • This reply was modified 9 years, 9 months ago by simoami.
    #20643
    FromH3ll
    Participant

    @simoni you f*cking rock bro!

    Thank you for the fix!

    #20664
    Maciej
    Participant

    United request to Simoami, I am a novice in PHP. Can you repeat the whole function code with the amendment? I tried to make it in Notepad ++, but I get the error “syntax error, unexpected T_CLASS” in line with the regular expression. Errors may come from the characters such as " , '
    I’ll be very grateful for your help.

    #20669
    Fladi
    Participant

    Thanks @simoami for the patch. Works great!


    @Maciej
    :

    function enlightenment_nav_menu_container_extra_atts( $nav_menu, $args ) {
            $atts = apply_filters( 'enlightenment_nav_menu_container_extra_atts', ' role="navigation"' );
            $nav_menu = preg_replace('/(class=\”[^"]*\”)/i', '\1' . enlightenment_extra_atts( $atts ), $nav_menu);
            return $nav_menu;
    }
    #20676
    Maciej
    Participant

    Thank you very much @Fladi, works like a charm. Straight out of the box.

    #20677
    simoami
    Participant

    Please be careful when copying code from this forum. it replaces " with

    Make sure to use " everywhere instead of

    Full code again:

    
    function enlightenment_nav_menu_container_extra_atts( $nav_menu, $args ) {
            $atts = apply_filters( 'enlightenment_nav_menu_container_extra_atts', ' role="navigation"' );
            $nav_menu = preg_replace('/(class=\"[^"]*\")/i', '\1' . enlightenment_extra_atts( $atts ), $nav_menu);
            return $nav_menu;
    }
    
    • This reply was modified 9 years, 9 months ago by simoami.
    • This reply was modified 9 years, 9 months ago by simoami.
    #20681
    ehd
    Participant

    Thank you Simoami for your fix. I have tried it and it is working. I am not familiar enough with child themes though to figure out how to implement this as part of the child theme versus the parent. Daniel, do you think you would be implementing Simoami’s fix in a future release?

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic.