custom sidebar in wordpress

How to create a sidebar

In a few simple steps we will show you how to create a new piece for the widgets section that you can activate or customize from the WordPress dashboard menu by following the Appearance / Pieces path, respectively a sidebar.

To get started, you’ll need to enter the following code into the theme’s functions.php file:

function bara_laterala_custom() {

	$args = array(
		'id'            => '22',
		'class'         => 'bara-laterala',
		'name'          => __( 'nume bara laterala', 'text_domain' ),
		'before_title'  => '<h2>',
		'after_title'   => '</h2>',
		'before_widget' => '<li>',
		'after_widget'  => '</li>',
	);
	register_sidebar( $args );

}
add_action( 'widgets_init', 'bara_laterala_custom' );

Short code description:

  1. Creating a function (we named it custom_side_bar (), but you can give it any name you want)
  2. Inside the function we will use the $ args array which will contain the following information:
    1. the unique id of the song
    2. the CSS class you want to use for later stylization
    3. part name (you can replace “sidebar name” with any other name you want)
    4. HTML tags for opening and closing the title, respectively
    5. the HTML tags that will apply to the content
  3. Registering the new track with the default WordPress function “register_sidebar ()” with the above values
  4. In order to activate it, after closing the above function, we will use a WordPress Action Hook, respectively add_action () which will contain at least two arguments: the first will tell you what type of action is invoked (in our case “widgets_init”) and the second will specify the function in which the sidebar was created.
Share: