Remove #top from WordPress Menu

Francis Begbie

Regular Member
Joined
May 4, 2019
Messages
263
Reaction score
65
Hi,

Is there a quick fix to remove /#top from WordPress URLs so that you can refresh a page when you are on it by clicking on the corresponding page in the top navigation?

Thanks
Tom
 
Sounds theme specific. I just checked a random WordPress site and it doesn't have an element with ID top.
 
Well, a quick and dirty way would be to traverse through the links and strip off the last 4 chars if it ends with #top...

Example (paste to your footer within script tag... Funny, cloudflare blocks me from posting script tag):

Code:
$(document).ready(function(){ 
    $(document).find('a').each(function(){
        if(typeof $(this).attr('href') == "undefined"){
            return;
        }
       if($(this).attr('href').endsWith('#top')){
            $(this).attr('href', $(this).attr('href').slice(0, -4));
       }     
    });
});

It may be inefficient. Although the inefficiency shouldn't really matter if you do not have 100000 links in one page.
 
Last edited:
Well, a quick and dirty way would be to traverse through the links and strip off the last 4 chars if it ends with #top...

Example (paste to your footer within script tag... Funny, cloudflare blocks me from posting script tag):

Code:
$(document).ready(function(){
    $(document).find('a').each(function(){
        if(typeof $(this).attr('href') == "undefined"){
            return;
        }
       if($(this).attr('href').endsWith('#top')){
            $(this).attr('href', $(this).attr('href').slice(0, -4));
       }   
    });
});

It may be inefficient. Although the inefficiency shouldn't really matter if you do not have 100000 links in one page.
Note to self: Don't help people for free. They don't even recognise it.. :weep::D:D:D
 
Sorry guys been busy thank you to all for your help!!
 
Back
Top