Skip to content

Instantly share code, notes, and snippets.

@webbyworks
Created September 7, 2013 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webbyworks/6472749 to your computer and use it in GitHub Desktop.
Save webbyworks/6472749 to your computer and use it in GitHub Desktop.
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