Nhiều Blogger đều ngán ngẩm với những liên kết cố định có chứa ngày tháng năm được Blogspot mặc định. Có thể nói ai sử dụng Blogspot đều mong muốn bỏ nó đi để liên kết trông đẹp mắt hơn. Trong bài viết này, Vinll sẽ hướng dẫn các bạn cách làm mất ngày tháng năm trong link bài viết.
Liên kết cố định trong Blogspot là gì?
Liên kết cố định hay còn gọi là Permalink là viết tắt của chữ Permanent Link. Thuật ngữ này được sử dụng để mô tả URL của một trang web như các trang tĩnh hay các bài đăng. Trong Blogger thì mặc định URL bài viết sẽ có ngày tháng năm và URL trang sẽ có chữ P.
Ví dụ:
- URL bài viết có dạng: https://vinll.blogspot.com/2018/07/code-widget-sitemap-effect-responsive.html
- URL trang có dạng: https://vinll.blogspot.com/p/about-us.html
Ví dụ:
- URL bài viết sẽ trở thành: https://vinll.blogspot.com/code-widget-sitemap-effect-responsive
- URL trang sẽ trở thành: https://vinll.blogspot.com/about-us
Cách ẩn ngày tháng năm trong URL Blogspot
Bước 1: Truy cập vào Blogger của bạn chọn Chủ đề -> Chỉnh sửa HTMLBước 2: Thêm code sao vào trước thẻ </body> hoặc trước thẻ </head>
<script type='text/javascript'>
//<![CDATA[
var urlTotal,nextPageToken,postsDatePrefix=!1,accessOnly=!1,useApiV3=!1,apiKey="",blogId="",postsOrPages=["pages","posts"],jsonIndex=1,secondRequest=!0,feedPriority=0,amp="&"[0];function urlVal(){var e=window.location.pathname,t=e.length;return".html"===e.substring(t-5)?0:t>1?1:2}function urlMod(){var e=window.location.pathname;"p"===e.substring(1,2)?(e=(e=e.substring(e.indexOf("/",1)+1)).substr(0,e.indexOf(".html")),history.replaceState(null,null,"../"+e)):(e=(e=postsDatePrefix?e.substring(1):e.substring(e.indexOf("/",7)+1)).substr(0,e.indexOf(".html")),history.replaceState(null,null,"../../"+e))}function urlSearch(e,t){var n=e+".html";t.forEach(function(e){-1!==e.search(n)&&(window.location=e)})}function urlManager(){var e=urlVal();0===e?accessOnly||urlMod():1===e?getJSON(postsOrPages[feedPriority],1):2===e&&(accessOnly||history.replaceState(null,null,"/"))}function getJSON(e,t){var n=document.createElement("script");if(useApiV3){var o="https://www.googleapis.com/blogger/v3/blogs/"+blogId+"/"+e+"?key="+apiKey+"#maxResults=500#fields=nextPageToken%2Citems(url)#callback=bloggerJSON";nextPageToken&&(o+="#pageToken="+nextPageToken),nextPageToken=void 0}else o=window.location.protocol+"//"+window.location.hostname+"/feeds/"+e+"/default?start-index="+t+"#max-results=150#orderby=published#alt=json-in-script#callback=bloggerJSON";o=o.replace(/#/g,amp),n.type="text/javascript",n.src=o,document.getElementsByTagName("head")[0].appendChild(n)}function bloggerJSON(e){var t=[];if(useApiV3||void 0===urlTotal&&(urlTotal=parseInt(e.feed.openSearch$totalResults.$t)),useApiV3){try{e.items.forEach(function(e,n){t.push(e.url)})}catch(e){}nextPageToken=e.nextPageToken}else try{e.feed.entry.forEach(function(n,o){var r=e.feed.entry[o];r.link.forEach(function(e,n){"alternate"===r.link[n].rel&&t.push(r.link[n].href)})})}catch(e){}urlSearch(window.location.pathname,t),urlTotal>150?(jsonIndex+=150,urlTotal-=150,getJSON(postsOrPages[feedPriority],jsonIndex)):nextPageToken?getJSON(postsOrPages[feedPriority]):secondRequest&&(nextPageToken=void 0,urlTotal=void 0,jsonIndex=1,secondRequest=!1,0===feedPriority?(feedPriority=1,getJSON("posts",1)):1===feedPriority&&(feedPriority=0,getJSON("pages",1)))}function bloggerJS(e){e&&(feedPriority=e),urlManager()}bloggerJS();
//]]>
</script>
Bước 3: Lưu lại và xem kết quả
Hiện tại, trang của Vinll không áp dụng cách trên là vì Vinll muốn để như vậy chứ không phải là không làm được nhé. Vinll đã sử dụng trên blog test và kết quả là đây.
Lưu ý: Đoạn code trên không thể ẩn search/label/
Hy vọng bài viết trên có thể giúp ích được phần nào đó cho các bạn. Mọi thắc mắc và phản hồi các bạn để lại trong bình luận nhé. Vinll sẽ giải đáp cho các bạn sớm nhất có thể.
Tags:
thu-thuat-blogspot