Title: Permalink and Year
Last modified: August 22, 2016

---

# Permalink and Year

 *  [efeoge](https://wordpress.org/support/users/efeoge/)
 * (@efeoge)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/permalink-and-year/)
 * Hi,
 * [Permalink tags](http://codex.wordpress.org/Using_Permalinks#Structure_Tags) 
   allow year only as a 4 digit number like 2014. I’d prefer to use last 2 digit
   year like 14 instead of 2014.
 * How to do?

Viewing 1 replies (of 1 total)

 *  [Ryan Sechrest](https://wordpress.org/support/users/sovereign/)
 * (@sovereign)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/permalink-and-year/#post-5615178)
 * Before we dive into that, it’s important to know that when WordPress receives
   a URL like this:
 * `example.org/2014/12/hello-world/`
 * There is a rewrite rule:
 * `[([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$] => index.php?year=$matches[1]&
   monthnum=$matches[2]&name=$matches[3]&page=$matches[4]`
 * That will convert the permalink to:
 * `example.org/?year=2014&monthnum=12&name=hello-world$page=`
 * Which is the basis of the database query:
 *     ```
       SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND (
         ( YEAR( wp_posts.post_date ) = 2014 AND MONTH( wp_posts.post_date ) = 12 )
       ) AND wp_posts.post_name = 'hello-world' AND wp_posts.post_type = 'post'  ORDER BY wp_posts.post_date DESC
       ```
   
 * WordPress also has built-in rules for URLs like:
 * `example.org/2014`
    `example.org/2014/12` `example.org/2014/12/hello-world/comments`
 * When changing something this ingrained, all those aspects would need to be accounted
   for when converting the default four-digit year to a two-digit year. With that
   in mind, my recommendation would be to keep it as-is.
 * That said, you posted this in the hacks forum, so you’re probably prepared that
   this might get messy. Read on.
 * Regardless of how you do this, you’ll need the [`post_link`](https://codex.wordpress.org/Plugin_API/Filter_Reference/post_link)
   filter to output the URL in a format of your choice.
 * The next step is ensuring that WordPress can still find your post.
 * If all your existing and future posts are between the year 2000 and 2999, you
   could prepend the “20” prior to making the query via [`pre_get_posts`](http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts).
 * You could also add new rewrite rules using the [`add_rewrite_rule`](http://codex.wordpress.org/Rewrite_API/add_rewrite_rule)
   function that prepends the “20” prior to making a query.
 * If you don’t want to hardcode the “20,” you could strip out the year all together
   using `pre_get_posts` and rely on WordPress to find your post with one less parameter(
   just month and post name).
 * This should give you a few ideas and a starting point.

Viewing 1 replies (of 1 total)

The topic ‘Permalink and Year’ is closed to new replies.

## Tags

 * [year](https://wordpress.org/support/topic-tag/year/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Ryan Sechrest](https://wordpress.org/support/users/sovereign/)
 * Last activity: [11 years, 5 months ago](https://wordpress.org/support/topic/permalink-and-year/#post-5615178)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
