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:
- Creating a function (we named it custom_side_bar (), but you can give it any name you want)
- Inside the function we will use the $ args array which will contain the following information:
- the unique id of the song
- the CSS class you want to use for later stylization
- part name (you can replace “sidebar name” with any other name you want)
- HTML tags for opening and closing the title, respectively
- the HTML tags that will apply to the content
- Registering the new track with the default WordPress function “register_sidebar ()” with the above values
- 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.