Many of the times, we saw that we are not able to do some very easy tasks. One of them is “Adding widgets in wordpressâ€. In this tutorial, I will show you how to “Add widgets in wordpressâ€.
Follow these steps:
Step1:
Open your function.php file and then copy and paste the following code in that file:
<?php function arphabet_widgets_init() { register_sidebar( array( 'name'=>'test_widget', 'id' => 'category' ) ); } add_action( 'widgets_init', 'arphabet_widgets_init'); ?>
Step 2:
Now Go to the admin section of your wordpress website and then go to Appearance/ widgets. There you will see the widget title with name “footerâ€. This was the name given in the code as ‘name’ => ‘footer’.
Step 3:
Now drag and drop the widgets you want to add to your widget area.
Step 4:
Now your widget is set. Its time to use those widgets in your page. To do so you have to open that page in which you want to show the widget. Generally, we add widgets to the sidebar or in the footer. In this tutorial, I am adding widget to the footer so I will open thefooter.php file and then add the following code to it.
<?php dynamic_sidebar( 'search' ); ?>
Note: Here ‘search’ is the id given in the code in function.php file as ‘id’ => ‘search’
Now your page is ready with your widget.