Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




register_sidebar [ WordPress Function ]

register_sidebar ( $args = array() )
Parameters:
  • (string|array) $args Builds Sidebar based off of 'name' and 'id' values
Uses:
  • $wp_registered_sidebars
Returns:
  • (string) The sidebar id that was added.
Defined at:



Builds the definition for a single sidebar and returns the ID.

The $args parameter takes either a string or an array with 'name' and 'id' contained in either usage. It will be noted that the values will be applied to all sidebars, so if creating more than one, it will be advised to allow for WordPress to create the defaults for you.

Example for string would be

'name=whatever;id=whatever1'

and for the array it would be

array(
   'name' => 'whatever',
   'id' => 'whatever1')

.

name - The name of the sidebar, which presumably the title which will be displayed. id - The unique identifier by which the sidebar will be called by. before_widget - The content that will prepended to the widgets when they are displayed. after_widget - The content that will be appended to the widgets when they are displayed. before_title - The content that will be prepended to the title when displayed. after_title - the content that will be appended to the title when displayed.

Content is assumed to be HTML and should be formatted as such, but doesn't have to be.

Source


<?php
function register_sidebar($args = array()) {
    global 
$wp_registered_sidebars;

    
$i count($wp_registered_sidebars) + 1;

    
$defaults = array(
        
'name' => sprintf(__('Sidebar %d'), $i ),
        
'id' => "sidebar-$i",
        
'description' => '',
        
'class' => '',
        
'before_widget' => '<li id="%1$s" class="widget %2$s">',
        
'after_widget' => "</li>\n",
        
'before_title' => '<h2 class="widgettitle">',
        
'after_title' => "</h2>\n",
    );

    
$sidebar wp_parse_args$args$defaults );

    
$wp_registered_sidebars[$sidebar['id']] = $sidebar;

    
add_theme_support('widgets');

    
do_action'register_sidebar'$sidebar );

    return 
$sidebar['id'];
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics