Remove Hash # from WordPress URLs with Simple Trick

jquery remove hash in URLSWhen creating custom WordPress pages that utilize jQuery for interactivity, you may encounter a common problem of a hash (#) sign added to your URLs. If you are looking for a way of removing the hash # added on URL in WordPress custom pages, here is a simple trick to help you remove this hash # on URLs.

Hash # Added to WordPress URL

The problem can best be described as the addition of a hash sign at the end of a URL example:

http://yourdomain.com/aboutus#

The hash sign at the end of the URL is not only ugly but hurting your site SEO structure; the only option we have is to get rid of it. Before we delve deeper into removing this hash sign and making our URL beautiful we should first understand what causes this hash sign at ends of URLs.

What Causes # At the End of URLs?

The default WordPress URLs will rarely have this hash; this problem is encountered when creating custom WordPress pages that are enhanced with Jquery. So this is a Jquery problem that is caused by actions that are associated with links

<a href='#'> </a>

Jquery appends a # sign on the current URL when clicked and there is a simple way to get rid of this menace.

What is the solution?

You should use preventDefault() the function that simply prevents Jquery from adding the # at the end of URLs. A simple script using this function will solve this problem, here is the script:

<script>

$('#yourlink').click(function(){

event.preventDefault();

//Removes hash from URLs...

});

</script>

Implementing in WordPress 

You should open your header.php file in your theme files and paste the code above somewhere in the header. This should help you get rid of the URL hash (#) sign. If you are still having a problem with this approach, you should leave a comment for me to help you.

Comments are closed.