How to remove date from WordPress Post URL

In this post we are sharing the steps to remove date from a WordPress post URL/permalink. We recently did this change in our own WordPress blog. It has been since long time we were using this date format in our blog permalink like this https://sharadchhetri.com/YYYY/MM/DD/post-slug . We decided to change the URL format in this way https://sharadchhetri.com/post-slug

To make this changes we have to work on Nginx Configuration and WordPress Admin console.

To change the WordPress Permalink, we will work on two areas which is our requirement.
1. Permalink settings change from WordPress Admin Console.
2. Updating Nginx configuration for redirection.

Do permalink settings change from WordPress Admin Console

To change the permalink settings we have to work on WordPress Admin Console. Login to WordPress Admin Dashboard. The login user should have admin privileges.

  • Login to your WordPress Blog Admin Dashboard. The login user should have Admin privileges.
  • Click on ‘Settings’ >> ‘Permalinks’
  • In “Permalink Settings” page, click on ‘Post name’ option.
    wordpress permalink
  • Click ‘Save Changes’

Using redirection in Nginx Configuration

Go for ‘redirection’ configuration in Nginx only when you want to redirect old permalink to new changed one.
We did this nginx configuration change only to keep our old blog URL to redirect to new URL. This will not affect our reader if they are coming from referrals. We have written the redirect in server block.

The redirect should be written inside the server or location block in Nginx configuration.

server {
   ....
    rewrite ^/([0-9]+)/([0-9]+)/([0-9]+)/(.*?)/?$  /$4 permanent;
   ....
}

Save the Nginx configuration.
Before restarting the nginx service, confirm first if configuration is correct. To check the Nginx configuration run the command sudo nginx -t. Restart the nginx service once the sudo nginx -t is OK.
nginx