Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 Aug 13 '12 at 13:52
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.