Create a Function to Create WordPress Widgets

I’ve taken to the practice of doing something like this whenever I need to create multiple widgets in a theme that all have the same basic parameters.

function create_widget($name, $id, $description) {

	register_sidebar(array(
		'name' => __( $name ),	 
		'id' => $id, 
		'description' => __( $description ),
		'before_widget' => ' ',
		'after_widget' => ' ',
		'before_title' => '<h5>',
		'after_title' => '</h5>'
	));

}

create_widget("Left Footer", "left_widget", "Displays in the left of the footer");

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s