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: when you update that post, what should you do? Leave it’s URL looking old? Move it to the new one and worry it’ll 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.

In this Quick Guide about WordPress, changing permalink structure will be our goal. The problem: while toggling the setting itself can work, will cause your WordPress site to present 404 errors at your old URLs. The trick we’ll cover in this video (and written tutorial about WordPress): URL rewrites with .htaccess files.

As always, we’ll start with this video. In this one I explain how I change permalink structure for WordPress posts, 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 date from WordPress post URLs 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 Date from WordPress Post URLs

So if you want to change your permalinks to remove post date in WordPress, here’re the steps we recommend you take:

  1. 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.
  2. 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.”
  3. 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.
  4. 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.
  5. 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>
  6. 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 🙂

2019-03-14T14:52:54-04:00