Add a custom widget area in WordPress

Published on September 11, 2019 at 3:16 pm by reMarkable websites

Firstly define the new widget area by adding the following to functions.php:-

function custom_widget_init() {
    register_sidebar( array(
        'name'          => 'Custom',
        'id'            => 'custom-widget-area',
        'before_widget' => '<div class="cwa">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="cwa-title">',
        'after_title'   => '</h2>',
    ) );
add_action( 'widgets_init', 'custom_widget_init' );

Now simply add this code where you would like the widget to appear:-

<?php dynamic_sidebar( 'custom-widget-area' ); ?>

Obviously you can replace ‘custom’ and ‘cwa’ with whatever you like.


Comments are closed here.

Back To Blog