Remove Date from Jekyll Posts

On This Page

When working with Jekyll, you may want to remove the date from your post URLs and filenames for a cleaner and more modern URL structure. This can be achieved differently depending on whether you’re working with collections or standard posts. Let’s explore these methods in detail.

For collections, like _blog, you can easily remove the date from the permalinks by setting the permalink attribute in your _config.yml file.

collections:
  blog:
    output: true
    permalink: /blog/:title

Create a New Post in Your Collection: When you create a new post in your _blog collection, you don’t need to include the date in the filename. Simply name it new-post.md.

When you build your site, the URL for this post will be /blog/new-post, without any dates.

The resulting URL for the post will be:

https://yourdomain.com/blog/new-post

Removing Dates from Standard Posts

For standard posts, such as those typically stored in _posts, Jekyll requires the date in the filename _posts/2024-06-29-new-post.md. To bypass this, you need a plugin.

Jekyll uses the date in the post filename to sort and organize posts. To remove the date and still maintain proper functionality, a plugin can intercept and adjust the filename and permalink structure.

Create the Plugin

Add a new file named nodates.rb in the _plugins directory of your Jekyll site _plugins/nodate.rb.

class Jekyll::PostReader
  def read_posts(dir)
    read_publishable(dir, "_posts", /.*\.(markdown|md)$/)
  end
  def read_drafts(dir)
    read_publishable(dir, "_drafts", /.*\.(markdown|md)$/)
  end
end

Remove Dates from Filenames: Rename your post files to remove the dates. For example, rename _posts/2024-06-29-new-post.md to new-post.md.

Update Configuration

Ensure your _config.yml does not enforce dates in the permalinks.

permalink: /:title

The resulting URL for the post will be:

https://yourdomain.com/new-post

Removing dates from Jekyll post URLs and filenames can make your URLs cleaner and more user-friendly. For collections, a simple configuration change is sufficient. For standard posts, using a plugin like nodates.rb is necessary to achieve the same result. By following the steps outlined above, you can easily remove dates from your Jekyll posts

Drop Your Email

Add Your Note