I want to use the [archives type=yearly]
short code on a side bar widget so that people can click on links and see posts for the year. But this is the result I'm getting:
This is what I'm doing in the Widgets Editor:
And I added add_filter( 'widget_text', 'do_shortcode' );
to wp-content/themes/twentysixteen/functions.php
.
I also get a similar problem when pasting the [archives]
into a page or post. The website just renders it at [archives]
.
If I enter a shortcode like [gallery]
, I see a gallery.
So the problem is with the [archives]
short code.
What am I doing wrong?
I want to use the [archives type=yearly]
short code on a side bar widget so that people can click on links and see posts for the year. But this is the result I'm getting:
This is what I'm doing in the Widgets Editor:
And I added add_filter( 'widget_text', 'do_shortcode' );
to wp-content/themes/twentysixteen/functions.php
.
I also get a similar problem when pasting the [archives]
into a page or post. The website just renders it at [archives]
.
If I enter a shortcode like [gallery]
, I see a gallery.
So the problem is with the [archives]
short code.
What am I doing wrong?
Share Improve this question edited Mar 17, 2022 at 13:34 learningtech asked Mar 17, 2022 at 12:52 learningtechlearningtech 1971 silver badge14 bronze badges1 Answer
Reset to default 0I don't know or understand why, but I pasted this into wp-content/themes/twentysixteen/functions.php
and it worked:
function wpse61674_archives_shortcode_cb( $atts ) {
return '<h2 class="widget-title">Archives</h2><ul>'.wp_get_archives(array('format'=>'html','echo'=>false,'type'=>'yearly')).'</ul>';
}
add_shortcode( 'archives', 'wpse61674_archives_shortcode_cb' );
I found this code somewhere on the internet, but it wasn't part of the wordpress documentation on archives shortcode.