Skip to:

Opened 14 years ago

Closed 13 years ago

Last modified 8 years ago

#2751 closed enhancement (fixed)

Add function around widgets in functions.php

Reported by: karmatosed's profile karmatosed Owned by: djpaul's profile DJPaul
Milestone: 1.5 Priority: normal
Severity: Version:
Component: Templates Keywords:


My suggestion is to wrap widgets in function to work better for child themes knowing when widgets are registered. It will also allow for ease of un registering.

Something along the lines of this....

function default_widgets_init() {

register_sidebar( array(
	'name'          => 'Sidebar',
	'before_widget' => '<div id="%1$s" class="widget %2$s">',
	'after_widget'  => '</div>',
	'before_title'  => '<h3 class="widgettitle">',
	'after_title'   => '</h3>'
) );

register_sidebar( array(
	'name' => __( 'First Footer Widget Area', 'buddypress' ),
	'id' => 'first-footer-widget-area',
	'description' => __( 'The first footer widget area', 'buddypress' ),
	'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
	'after_widget' => '</li>',
	'before_title' => '<h3 class="widgettitle">',
	'after_title' => '</h3>',
) );

... other widgets

add_action( 'widgets_init', 'default_widgets_init' );

Change History (4)

#1 @nacin
14 years ago

Widgets should be registered on widgets_init anyway, so +1.

#2 @DJPaul
14 years ago

  • Owner set to DJPaul
  • Status changed from new to assigned

Yes, I'm working on this but it affects a few other things so I need to hit them all at one time

#3 @djpaul
13 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [3496]) Refactor functions.php to use appropriate theme-loading actions.
Improved support for custom thumbnails; now supports global page header as well as a per-post/page header.
Key functions are now hookable.
Add full phpDoc.
Props to the WordPress team and Twenty Ten for some of the phpDoc.
Fixes #2749, #2754, #2751.

#4 @DJPaul
8 years ago

  • Component changed from Appearance - Template Parts to Templates
Note: See TracTickets for help on using tickets.