0

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');
3
  • 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. Commented Aug 13, 2012 at 13:35
  • I see, I'll have to think up about naming conventions from now on.
    – Ryu
    Commented Aug 13, 2012 at 13:39
  • If you are using PHP 5.3, look into namespacing. Commented Aug 13, 2012 at 13:52

1 Answer 1

2

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' );
1
  • Thanks that worked. I was wrong with add_action function.:)
    – Ryu
    Commented Aug 13, 2012 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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