-
ehd
ParticipantI 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 10 years, 2 months ago by ehd.
Daniel Tara
KeymasterThere is currently a bug when adding navigation menus to sidebars. It will be fixed in the next version that will be released shortly.
SharkBait
ParticipantHi,
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!!
Daniel Tara
KeymasterThis 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.
simoami
ParticipantI 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.
simoami
ParticipantHere’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!
simoami
ParticipantSorry, 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 10 years, 1 month ago by simoami.
Maciej
ParticipantUnited 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.Fladi
ParticipantThanks @simoami for the patch. Works great!
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; }
simoami
ParticipantPlease 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; }
ehd
ParticipantThank 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?
Tagged: custom menu, pages, sidebar, URL
You must be logged in to reply to this topic.