WordPress函数register_sidebar


Updated on: September 14, 2020 in wpfunctions by

register_sidebar( array|string $args = array() )

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

Description #Description

Accepts either a string or an array and then parses that against a set of default arguments for the new sidebar. WordPress will automatically generate a sidebar ID and name based on the current number of registered sidebars if those arguments are not included.

When allowing for automatic generation of the name and ID parameters, keep in mind that the incrementor for your sidebar can change over time depending on what other plugins and themes are installed.

If theme support for ‘widgets’ has not yet been added when this function is called, it will be automatically enabled through the use of add_theme_support()


Top ↑

Parameters #Parameters

$args

(array|string) (Optional) Array or string of arguments for the sidebar being registered.

  • ‘name’
    (string) The name or title of the sidebar displayed in the Widgets interface. Default ‘Sidebar $instance’.
  • ‘id’
    (string) The unique identifier by which the sidebar will be called. Default ‘sidebar-$instance’.
  • ‘description’
    (string) Description of the sidebar, displayed in the Widgets interface. Default empty string.
  • ‘class’
    (string) Extra CSS class to assign to the sidebar in the Widgets interface.
  • ‘before_widget’
    (string) HTML content to prepend to each widget’s HTML output when assigned to this sidebar. Default is an opening list item element.
  • ‘after_widget’
    (string) HTML content to append to each widget’s HTML output when assigned to this sidebar. Default is a closing list item element.
  • ‘before_title’
    (string) HTML content to prepend to the sidebar title when displayed. Default is an opening h2 element.
  • ‘after_title’
    (string) HTML content to append to the sidebar title when displayed. Default is a closing h2 element.

Default value: array()


Top ↑

Return #Return

(string) Sidebar ID added to $wp_registered_sidebars global.


Top ↑

Source #Source

File: wp-includes/widgets.php