Skip to content

Instantly share code, notes, and snippets.

@jpen365
Created December 17, 2016 03:51
Show Gist options
  • Save jpen365/8d17ce2c8d210d1cae1cca95cc7a1d7a to your computer and use it in GitHub Desktop.
Save jpen365/8d17ce2c8d210d1cae1cca95cc7a1d7a to your computer and use it in GitHub Desktop.
One-page nav code for twenty seventeen
/*
One page nav code
*/
jQuery( document ).ready(function(){
/* Add padding and id's to each front page section */
jQuery( "h2.entry-title" ).each( function() {
var panelId = jQuery( this ).html().toLowerCase().replace(/\s+/g, "-");
jQuery( this ).wrapInner(function() {
return "<span style='padding-top:96px;' id='" + panelId + "'></span>";
})
})
/* Remove navigation link highlighting */
jQuery('#top-menu li').removeClass('current-menu-item current_page_item ');
/* Add highlighting on click */
jQuery('#top-menu li a').on('click', function(event) {
jQuery(this).parent().parent().find('li').removeClass('current-menu-item');
jQuery(this).parent().addClass('current-menu-item');
});
/* Check current URL and highlight nav for current page */
jQuery('#top-menu li a').each( function() {
var pageUrl = jQuery( location ).attr( 'href' );
var navUrl = jQuery( this ).attr( 'href' );
if ( navUrl == pageUrl ) {
jQuery( this ).parent().addClass('current-menu-item');
}
})
})
@tuncay1984
Copy link

Thank you so much

@megrimm
Copy link

megrimm commented Jul 28, 2017

hi... how would i be able to "jump" from a page that is not a part of the one page navigation back to an area that is a part of the one page nav? Right not if I am on a page that is seperate from the front page (one page nav) the it just goes back to the top of the page instead of the wordpress/#foo page area...

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment