Have you ever think of How To Get Rid Of Numbers in Blogger Post URL. If you want to have a professional look for your blogger blog, you must erase the number part from your blog's post or page URL. Numbers in the blogger post & page URL is annoying for most of the blogger who want to use blogger blog as a real website except those who used to write bog posts as a diary. Who want to use blogger as a professional site must remove the number part from the blogger post or page URL. It is unfortunate that blogger does not support post's URL customization as you like. But, wordpress supports fully customization, that is why wordpress is so popular among the blog writers.
What is Blogger post Permalink or URL?
When a post or page is published, a permanent url is selected for the post or page. This permalink is your post's unique web address.
How the permalink looks
A blogger post permalink consist of three two parts. First part shows the year and month of the published post. That is it consists of numbers and second part is composed of words that is used in title of our article.
Why the numbers are there
Blogger was constructed with the purpose of personal blogging in a manner people wield a diary.
Blogger has limited features and customization. It is hosted on the Google's Server and not available to host on your server. So, we have no access over it's base. But, HowBloggerCode has cracked all the limitation. Today we are sharing, How to delete the number part from blogger post address.
What to do to remove it
We are sharing this tutorial in a learning manner. First we have to remember that we can use any code from client side not from serve side. i.e. our selected code should be processed by browsers not by any servers.
It is not to mention that we should place our whatever code to the top of our template i.e. <HEADER> </HEADER> section so that browsers processed the code as early as possible before any other element or style or function loads.
The usual URL of any Blogger post looks like:
https://blog.mrinmoy.com/2014/06/sample-post.html
After Placing our code blogger post URL looks like this:
https://blog.mrinmoy.com/sample-page/
//OR
https://blog.mrinmoy.com/sample-page.html
Before:
A blogger page URL is like that:
https://blog.mrinmoy.com/p/about.html
After:
https://blog.mrinmoy.com/about.html
or https://blog.mrinmoy.com/about/
Now, we have to retrieve the URL of the blogger post or page.
document.location.href returns full URL.
//OR
https://blog.mrinmoy.com/sample-page.html
Before:
A blogger page URL is like that:
https://blog.mrinmoy.com/p/about.html
After:
https://blog.mrinmoy.com/about.html
or https://blog.mrinmoy.com/about/
Now, we have to retrieve the URL of the blogger post or page.
document.location.href returns full URL.
document.location.href = "https://blog.mrinmoy.com/2014/06/welcome-to-mrinmoy.html"
document.location.hostname = "blog.mrinmoy.com"
document.location.pathname = "/2014/06/welcome-to-mrinmoy.html"
we can use window instead of document for cross-browsers safety.
window.location.pathname returns the same result as document.location.pathname that is why
window.location.pathname === document.location.pathname returns true
so, we are using window.location.pathname to retrieve the required path.
Now, we have to remove the /2014/06/ part from the path.
Now, put the required pathname to a variable path.
var path = window.loacation.pathname;
now lastIndexOf("/") finds the position of "/".
var pos = path.lastIndexOf("/");
this returns 8 in case pathname is like: /2014/06/how-to-do-it.html
/ 2 0 1 4 / 0 6 / counts 8.
now we have to get the part after "/" so we are using substr() method.
var slug = path.substr(pos); returns how-to-do-it.html
Now delete the .html part and replace it with "/"
var url = slug.replace(".html","/");
Now the value of url is /how-to-do-it/
Replace the previous path name with our new pathname i.e url variable.
We cannot use window.location.pathname = url ; to update the pathname because it reloads the page. Instead we can use history.pushState("var","var","var"); method to change the pathname.
history.pushState("","",url);
It updates the pathname with new one.
Give me the code to Paste:
So, here is the complete code:
<script>
//****HowBloggerCode Script strats******
//Copyright 2014 HowbloggerCode
var path = window.location.pathname;
var pos = path.lastIndexOf("/");
var slug = path.substr(pos);
var url = slug.replace(".html","/");
history.pushState("","",url);
//***HowBloggerCode Script ends******
</script>
if you want compressed script for fast loading, here it is:
<script>var path = window.location.pathname;
history.pushState("","",path.substr(path.lastIndexOf("/")).replace(".html","/"));
</script>
Limitation of this process:
Limitation is a major factor that is why bloggers conscious of SEO don't use this method to hide number parts from blogger url.
Limitation of this process:
Limitation is a major factor that is why bloggers conscious of SEO don't use this method to hide number parts from blogger url.
No comments:
Post a Comment