Support » How-To and Troubleshooting » wp_get_archives year rewriting help

wp_get_archives year rewriting help

  • Hello,

    I’m having a little problem trying to rewrite/reformat the year in my archives.

    For now it’s listing like January 2009
    and I d’like to display it like January ’09

    Moreover, is it possible to add a separate symbol between every months like : December ’09 / January ’09 / …..

    Big big thanks if you can help.


Viewing 5 replies - 1 through 5 (of 5 total)
  • Here’s one way to to do it. Replace wp_get_archives() with the following:

    echo preg_replace(
    	'#(' . implode('|', array_values($GLOBALS['wp_locale']->month)) . ')\s\d{2}(\d{2})#',
    	'$1 ’$2 /',

    Hello, huge thanks to you, you made my day man, can I ask something more so that I learn ?
    Can you maybe explain me what you did because that code seems so strange to me…
    Usually I understand the common wp php syntaxes but I gotta say I’m kinda stuck and it’s always nice to know.
    Thank you!

    implode('|', array_values($GLOBALS['wp_locale']->month))

    That basically makes a string of all the months, like so:


    preg_replace is a function that looks for a pattern—called a “regular expression”—and replaces it with something else. In this case, it looks for a month pattern (from that string above) followed by a four-digit number (presumably a year) and then replaces it with the month followed by the right single quote and the last two digits of the year.

    In wp_get_archives('echo=0') the echo=0 argument basically just tells wp_get_archives to return its string instead of printing it; that way we can use it in preg_replace.


    how would I go about changing the month to the abbreviated form in this rewrite in my archives.
    I’d like to display it like Jan ’09
    I just don’t know what I’m missing. Help would be really appreciated.


    I just made a post on my blog about how to edit date formatting for wp_get_archives. Should answer your question, lightback. It involves going into wp-includes which isn’t ideal due to WP updates, but it’s probably less “messy” than the theme alternatives. Hope this helps!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp_get_archives year rewriting help’ is closed to new replies.