最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

widgets - How to enable [archives] short code

programmeradmin5浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

I 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.

发布评论

评论列表(0)

  1. 暂无评论