Javascript 使用jQuery(在wordpress上)将粗体链接到父URL

Javascript 使用jQuery(在wordpress上)将粗体链接到父URL,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我用这个(见下面的代码)来加粗当前页面的链接。例如 (以章节名称为例) 这将加粗指向当前页面的所有链接,但我想将其修改为加粗指向父页面的所有链接(): 只是一个小小的改变 jQuery(document).ready(function( $ ) { $("header a").each(function(){ // if ($(this).attr("href") == window.location.pathname){

我用这个(见下面的代码)来加粗当前页面的链接。例如 (以章节名称为例)

这将加粗指向当前页面的所有链接,但我想将其修改为加粗指向父页面的所有链接():

只是一个小小的改变

jQuery(document).ready(function( $ ) {

       $("header a").each(function(){
               // if ($(this).attr("href") == window.location.pathname){
               if ($(this).attr("href") == window.location.pathname.slice(0, window.location.pathname.lastIndexOf('/'))){
                       $(this).addClass("current-second-menu");
               }
       });
});
jQuery(document).ready(function( $ ) {

       $("header a").each(function(){
               // if ($(this).attr("href") == window.location.pathname){
               if ($(this).attr("href") == window.location.pathname.slice(0, window.location.pathname.lastIndexOf('/'))){
                       $(this).addClass("current-second-menu");
               }
       });
});