How to Add an Image in WordPress Sidebar Widget

How to Add Widgets to WordPress Theme’s

0 Shares
0
0
0
0
0
0
0

There are really three main parts to introducing a footer sidebar/widget area in your theme:

  1. Registering the Sidebar(s) in the WordPress Theme
  2. Inserting the Sidebars In the WordPress Theme
  3. Putting some style into the sidebars

WordPress has introduced a few new functions recently which makes it hard to write one tutorial that will cater to every theme out there. I have broken this tutorial into smaller sections to cater for the various different themes.

Keep a backup copy of your “functions.php” and “footer.php” file just in case you make a mistake when making the code changes. Keep a backup copy of your “functions.php” and “footer.php” file just in case you make a mistake when making the code changes.

Adding Footer Widget to a Modern Theme

Open function.php

Search for “register_sidebar”

Copy

register_sidebar(array(
	'id' => 'sidebar1',
	'name' => __('Sidebar 1', 'tejashme'),
	'description' => __('The first (primary) sidebar.', 'tejashme'),
	'before_widget' => '<div id="%1$s">',
	'after_widget' => '</div>',
	'before_title' => '<h4>','after_title' => '</h4>',
));

Paste It

register_sidebar(array(
	'id' => 'yoursidebar',
	'name' => __('Your Sidebar Name', 'tejashme'),
	'description' => __('Your Sidebar Desciption', 'tejashme'),
	'before_widget' => '<div id="%1$s">',
	'after_widget' => '</div>',
	'before_title' => '<h4>',
	'after_title' => '</h4>',
));

Show the widget area in your theme

Put below code where you want to add widgets

<div id="ClassofSidebar"> <!-- for your Designing Purpose -->
	<?php
		if(is_active_sidebar('yoursidebar')){
			dynamic_sidebar('yoursidebar');
		}
	?>
</div>

Style the widget area to your liking

Create Class for “ClassofSidebar” in your style.css

#ClassofSidebar{
}

You are ready to use your new widgets
Thanks

Be Happy

Leave a Reply

Your email address will not be published. Required fields are marked *