I am using the following code to show the archive link by month.

<?php wp_get_archives('type=monthly&limit='.date('m').'&show_post_count=1'); ?>

but it shows as

  • december 2013 (3)
  • november 2013 (2)

but i need to just months only as..

  • december (3)
  • november (2)

how can I do that in some easy steps?


You could use a regexp to remove the year, though it's a little hacky:

$string = wp_get_archives('type=monthly&limit=20&echo=0');
$pattern = ' ((19|20)\d{2}(</a>))';
echo preg_replace($pattern, '\\3', $string);

Answer from this stackoverflow question:


| improve this answer | |
  • it's working very fine. but I dont understand the code. could you please explian it? – Riffaz Starr Dec 17 '13 at 13:17
  • What this code does is it returns your archive list as a plain html string, and then uses a regular expression (like find and replace) to remove any occurrences of 'date' from it. ' (19|20)\d{2}' means look for a space followed by either 12 or 20, and select it + the next two digits after removing the dates in brackets it echoes the list to the DOM You can experiment with regular expressions here: phpliveregex.com – Gaffen Dec 17 '13 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.