WordPress Widgets Init Function (Array Based)

function rational_widgets_init() { global $theme_text_domain; // defined at the top of the functions.php file $sidebars = array( 'header-1' => array( 'name' => 'Header', 'description' => 'Banner placement', 'class' => false, 'before_widget' => false, 'after_widget' => false, 'before_title' => false, 'after_title' => false, ), /* 'id' => array( 'name' => '', 'description' => '', 'class' => '', 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', ), */ ); foreach ($sidebars as $sidebar_id => $sidebar_args) { $sidebar_args['id'] = $sidebar_id; $sidebar_args['name'] = __( $sidebar_args['name'], $theme_text_domain ); if ($sidebar_args['description']) { $sidebar_args['description'] = __( $sidebar_args['description'], $theme_text_domain ); } register_sidebar( $sidebar_args ); } } add_action( 'widgets_init', 'rational_widgets_init' );

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.