Creating custom sidebar wordpress

给你一囗甜甜゛ 提交于 2019-12-08 13:48:40

问题


I want to create custom right sidebar for my wordpress site.

Something like this wordpress_right_sidebar

  1. It should be totally responsible.
  2. I'm going to post more items.
  3. What are the things i gotta need?

回答1:


Add this code into functions.php in order to register your custom sidebar:

function my_custom_sidebar() {
    register_sidebar(
        array (
            'name' => __( 'Custom', 'your-theme-domain' ),
            'id' => 'custom-side-bar',
            'description' => __( 'Custom Sidebar', 'your-theme-domain' ),
            'before_widget' => '<div class="widget-content">',
            'after_widget' => "</div>",
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        )
    );
}
add_action( 'widgets_init', 'my_custom_sidebar' );

I want to render the custom sidebar in single posts only, so I'll edit the "Single post" file in single.php

<?php if ( is_active_sidebar( 'custom-side-bar' ) ) : ?>
    <?php dynamic_sidebar( 'custom-side-bar' ); ?>
<?php endif; ?>
  • Go to Appearance > Widgets to see if the new sidebar available.
  • Add the widgets you need.


来源:https://stackoverflow.com/questions/43932377/creating-custom-sidebar-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!