how to create a sidebar in wordpress without plugin

How to create sidebar in wordpress without plugin?

In this article we will teach you how to create sidebar in wordpress without plugin.

Sometimes we need to add recent posts, google ads, subscription form, social media links, custom menus, custom links. Or any other modules to our website or blog. So, we can do these features by adding the widgets to our sidebars. Then we needs a sidebars which can be done with or without plugin.

Registering Sidebars or Widget Areas in WordPress

If you want to add or register sidebars to your website without plugin. Then paste the code given below in your functions.php file located at website_root_path/wp-content/themes/your_theme/functions.php

function rmc_sidebar_init() {

    register_sidebar( array(
        'name' => __( 'Your Sidebar Name', 'wpb' ),
        'id' => 'your-sidebar-1',
        'description' => __( 'This is your sidebar description.', 'rmc' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );

}

add_action( 'widgets_init', 'rmc_sidebar_init' );

In the code above we have used wordpress hook widgets_init. Because it will call our function rmc_sidebar_init after all wordpress widgets registered. We have used register_sidebar function to register our sidebar. And ‘rmc’ is our textdomain you can leave it blank. And You can find textdomain in your style.css file located at your theme directory.

Adding or Showing Dynamic Sidebars in WordPress Template or Theme Files

Now we need to show our sidebar in our wordpress’s template. We can show our sidebar anywhere like header, footer, left sidebar, right sidebar.

For example we want to show sidebar in our all pages. Then paste the code given below in your page.php file located at website_root_path/wp-content/themes/your_theme/page.php where you want your sidebar.

<?php if ( is_active_sidebar( 'your-sidebar-1' ) ) : ?>
    <div id="your-sidebar" class="widget-area" role="complementary">
    <?php dynamic_sidebar( 'your-sidebar-1' ); ?>
    </div>
<?php endif; ?>

In the above code we have used the function is_active_sidebar to check our sidebar is registered. Then we have used function dynamic_sidebar to call or show our sidebar.

That’s it you have learned how to create sidebar in wordpress without plugin. Using this code you can create a footer sidebar in wordpress without plugin, header sidebar in wordpress without plugin, menu sidebar in wordpress without plugin, widgets sidebar in wordpress without plugin or any custom sidebars in wordpress without plugin.

If you want more tutorials and tricks about wordpress then visit our WordPress Page and follow us on facebooktwittertumblrlinkdedin and if you like this article then share this.

ReadyMadeCode
Author: ReadyMadeCode

ReadyMadeCode.com is a website where you can find Free Online Tutorials - Website Development Tutorials, App Development Tutorials, Coding Tutorials,Website Designing and Development From popular programming languages or scripts or framework like php, laravel, html, css, javascript, nodejs, java, angularjs etc. Download Emails | E-Books.

View All Posts From ReadyMadeCode
Author Website : https://www.readymadecode.com
Scroll to top

Subscribe For Latest Updates

Enter your email address to subscribe and receive notifications of posts & updates by email.


Want a Website / App / Digital Marketing Solution

Website & App Development Packages

%d bloggers like this:
We have updated our memberships. Please check here
Close X