WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I checked that there is an shortcode on wordpress.com but it seems there is no build in way of adding the shortcode of archive on wordpress.org site. I know there was one plugin in repo but it's 2 years old with no updates in code.

So let's say if i want to return the archive. following shortcode doesn't work. Is there anything I am missing? Or is there any way to make this work?

 function archive{

 return '<?php wp_get_archives('type=monthly'); ?>';

 add_action('archives', 'archive');
share|improve this question
You should avoid generic function names like archive. This will cause a fatal error if a plug-in/theme/WordPress defines a function of the same name. – Stephen Harris Aug 13 '12 at 13:35
I see, I'll have to think up about naming conventions from now on. – Ryu Aug 13 '12 at 13:39
If you are using PHP 5.3, look into namespacing. – Joseph Leedy Aug 13 '12 at 13:52
up vote 2 down vote accepted

That is not a shortcode. Take a look at the Shortcode API for examples of how to do this.

Here is your specifc example:

function wpse61674_archives_shortcode_cb( $atts ) {
    return wp_get_archives('type=monthly');
add_shortcode( 'archives', 'wpse61674_archives_shortcode_cb' );
share|improve this answer
Thanks that worked. I was wrong with add_action function.:) – Ryu Aug 13 '12 at 13:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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