Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This jQuery snippet allows you to populate a sidebar widget containing ul.sidebar-nav-menu
<script>
(function($) {
"use strict";
$( function() {
// sub-menu areas into sidebar-nav-menu
if ( $("body.home").length === 0 ) {
var navTitle;
if ( $("ul.menu > li.current-menu-item").length > 0 ) {
navTitle = $("ul.menu > li.current-menu-item > a").text();
$("#sidebar h4.widget-title").first().text(navTitle + " Section");
$("ul.sidebar-nav-menu").append(
'<li><a href="' + $("li.current-menu-item > a").attr("href") + '" class="right-arrow">' +
navTitle + '</a></li>'
);
$("ul.menu > li.current-menu-item ul.sub-menu li a").each( function( i ) {
$("ul.sidebar-nav-menu").append(
'<li><a href="' + $(this).attr("href") + '" class="right-arrow">' +
$(this).text() + '</a></li>'
);
});
} else if ( $("ul.menu > li.current-page-ancestor").length > 0 ) {
navTitle = $("ul.menu > li.current-page-ancestor > a").text();
$("#sidebar h4.widget-title").first().text(navTitle + " Section");
$("ul.sidebar-nav-menu").append(
'<li><a href="' + $("li.current-page-ancestor > a").attr("href") + '" class="right-arrow">' +
$("li.current-page-ancestor > a").text() + '</a></li>'
);
$("ul.menu > li.current-page-ancestor ul.sub-menu li a").each( function( i ) {
$("ul.sidebar-nav-menu").append(
'<li><a href="' + $(this).attr("href") + '" class="right-arrow">' +
$(this).text() + '</a></li>'
);
});
}
}
// end sub-menu
});
}(jQuery));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.