How to Remove the Date from a WordPress Post URL

So, you want to remove the date from your WordPress post URLs? I get it. Those /2016/07/09/post-slug
URLs that seemed pretty cool when you (or someone else) set it up get old.
The primary reason those date URLs are an issue: when you update that post, what should you do? Leave it’s URL looking old? Move it to the new one and worry the link will break? These concerns are why we use the “Post name” option for WordPress permalinks here at WPShout and encourage most of our clients to do the same.
Step One in Rewriting WordPress Permalinks: Do No Harm (To Your Site’s SEO)
In this Quick Guide we cover how to change a WordPress permalink structure. The problem: while toggling the setting itself can work, will cause your WordPress site to present 404 errors at your old URLs.
What’s wrong with that? It will tank the SEO of the site you’re working on. If you’re curious what that means, we strongly suggest you read our article on WordPress SEO mistakes before moving further.
How to Rewrite WordPress URLs
The trick we’ll cover here to avoid generating 404s on our site: we’ll do our URL rewrites with .htaccess
files.
Here’s a video explaining how I change permalink structure for a WordPress post, and make sure that I forward all the traffic to the old URLs to the new ones:
WordPress URL rewrite with .htaccess
: the Code
When I simply remove post dates from URLs, WordPress is confused. It knows my “new” permalink settings, but it immediately forgets the old one. So we have to help it, that’s where this URL rewrite in .htaccess
rule comes in: it’ll make sure that WordPress never sees our old permalink structure. Here’s the code, which you’ll typically put in a file called .htaccess
which will be at the root of your WordPress site’s file system:
## To change example.com/2019/01/01/post-slug to example.com/post-slug
<IfModule mod_rewrite.c>
RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$4 [R=301,NC,L]
</IfModule>
The really important thing about this code: it requires that your WordPress server be running “Apache” not “Nginx,” and that your Apache configuration support .htaccess
files for URL rewrites. I mention this because this is the only way to remove the date from a WordPress post URL we’ll cover in this Quick Guide. But if you’re struggling, hopefully that gives you some helpful pointers on where to look next.
Step-by-Step Guide to Remove the Date from a WordPress Post URL
So if you want to change your permalinks to remove post date in WordPress, here’re the steps we recommend you take:
- First, you’ll want to change the permalink settings. To do that, navigate to “Settings > Permalinks” in the left bar of the WordPress admin area.
- The rest of this tutorial assumes that you’ve chosen URLs like
mysite.com/post-slug
. If you do want that URL structure for WordPress, select “Post name” (the fifth option as I write this) on the Permalink Settings page. Press “Save Changes.” - Now, to supper WordPress, we’ll do a URL rewrite with htaccess. As mentioned above (don’t worry if you didn’t use it) to change the change permalink structure for WordPress posts, we’ll need to find the .htaccess file. This is most easily done by first connecting to your web host via SFTP. If you’re new to that, here’s a guide.
- Once connected, find the
.htaccess
file at the root of your WordPress installation. Here’s where we’ll put the code to change our permalink structure for WordPress to remove the date. - URL rewriting is doing by
.htaccess
for *most* WordPress sites. So we’ll open up that file, and paste in these lines:## To change example.com/2019/01/01/post-slug to example.com/post-slug <IfModule mod_rewrite.c> RewriteRule ^([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /$4 [R=301,NC,L] </IfModule>
- Save and upload that file back to the server. With that, you should have successfully removed the date from your WordPress post URLs, without triggering a bunch of 404 errors.
Changing permalink structures in WordPress can be daunting, but hopefully we’ve guided you through. 🙂 If this is a new topic to you, we again strongly recommend you read up on SEO mistakes before attempting something like this the first time, as they’re one of the few types of mistakes in WordPress that can be impossible to quickly fix.
“My Developer Ruined My Site’s SEO”: Three Huge SEO Mistakes and How to Avoid Them
Add a Comment