Last active
December 13, 2016 04:18
-
-
Save zeshanshani/82ddb606fee26b1b3ae0271ee4746b69 to your computer and use it in GitHub Desktop.
Adding Full Absolute URLs to the Anchor Links in the Navbar that are not on the same page. Works best with the parent menu and sub-menu links in the navbar. And for WordPress navbar especially.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adding Full Absolute URLs to the Anchor Links in the Navbar that are not | |
* on the same page. Works best with the parent menu and sub-menu | |
* links in the navbar. And for WordPress navbar especially. | |
* | |
* Replace #parent_links_selector with the parent links selector | |
*/ | |
jQuery(document).ready(function($) { | |
$('#parent_links_selector').each(function(i, el) { | |
var $el = $(el), | |
elHref = $el.attr('href'), | |
pathname = document.location.pathname; | |
if ( elHref.indexOf( pathname.slice(0,-1) ) < 0 ) { | |
$el.siblings('.sub-menu').find('a[href^="#"]').each(function(i, el) { | |
$(el).attr('href', function(i, href) { | |
return elHref + href; | |
}); | |
}).on('click', function() { | |
return true; | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment