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.
/**
* 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;
});
}
});
});