Getting started with WordPressget_bloginfo()Enqueuing scriptsMaking network requests with HTTP APIEnqueuing Styleshome_url()Custom Post Typestemplate_includeThe Loop (main WordPress loop)AJAXThe $wpdb ObjectActions and Filterswp_get_current_user()Add/remove contact info for users with user_contactmethods filter hookCreating a custom templateCustomizer Hello WorldCustomizer Basics (Add Panel, Section, Setting, Control)The Admin Bar (aka "The Toolbar")Querying postsAlternating main loop (pre_get_posts filter)ShortcodeCreate a Post Programmaticallyget_template_part()Taxonomiesget_template_part()ShortcodesPost FormatsCustom exerpts with excerpt_length and excerpt_morePlugin developmentSecurity in WordPress - EscapingTemplate hierarchyRemove Version from Wordpress and StylesheetsChild Theme Basicsadd_action()get_template_part()Shortcode with attributeSidebarsSecurity in WordPress - SanitizationinitCreate Template for Custom Post TypeFunction: add_action()Add ShortcodeHow Can I integrate Markdown editor with Advance Custom Field's repeater Add-on.Installation and Configurationwp_get_current_user()WP-CronSecure your installationOptions APIFunction : wp_trim_words()WP_Query() LoopUpdate WordPress ManuallyThemesWP-CLIDebuggingadd_menu_page()add_submenu_page()get_option()get_permalink()get_the_category()the_title()get_the_title()add_editor_style()add_theme_support()WordPress Plugin creationRun WordPress local with XAMPPAdmin Dashboard WidgetsSite MigrationMeta BoxRemove Auto Line Breaks From Content and Excerptget_home_path()Wordpress theme and child-theme developmentREST API

Sidebars

Other topics

Remarks:

Argument options are:

  • name - Sidebar name (default: localized 'Sidebar' and numeric ID).
  • id - Sidebar id - Must be all in lowercase, with no spaces (default: a numeric auto-incremented ID). If you do not set the id argument value, you will get E_USER_NOTICE messages in debug mode, starting with version 4.2.
  • description - Text description of what/where the sidebar is. Shown on widget management screen. (Since 2.9) (default: empty)
  • class - CSS class to assign to the Sidebar in the Appearance -> Widget admin page. This class will only appear in the source of the WordPress Widget admin page. It will not be included in the front end of your website. Note: The value sidebar will be prepended to the class value. For example, a class of tal will result in a class value of sidebar-tal. (default: empty).
  • before_widget - HTML to place before every widget (default: <li id="%1$s" class="widget %2$s">) Note: uses sprintf for variable substitution
  • after_widget - HTML to place after every widget (default: </li>\n).
  • before_title - HTML to place before every title (default: <h2 class="widgettitle">).
  • after_title - HTML to place after every title (default: </h2>\n).

Registering sidebars

In your functions.php you can register new sidebars with this code

/**
 * Registers sidebars
 *
 * @param array Array with default or specified array values
 * @since       1.0.0
 */
if ( function_exists( 'register_sidebar' ) ) {
    register_sidebar( array (
        'name'          => esc_html__( 'Primary Sidebar', 'mytheme'),
        'id'            => 'primary-widget-area',
        'description'   => esc_html__( 'The Primary Widget Area', 'mytheme'),
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<div class="sidebar-widget-heading"><h3>',
        'after_title'   => '</h3></div>',
    ) );

    register_sidebar( array (
        'name'          => esc_html__( 'Secondary Sidebar', 'mytheme'),
        'id'            => 'secondary-widget-area',
        'description'   => esc_html__( 'The Secondary Widget Area', 'mytheme'),
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<div class="sidebar-widget-heading"><h3>',
        'after_title'   => '</h3></div>',
    ) );
}

You can add as many sidebars as you want to.

Get Sidebar

You can also create your own sidebar file in the theme to call it on different templates. Copy and paste sidebar.php of current theme and change the name (i.e. sidebar-book.php)

In the template you can call this sidebar using get_sidebar('book'). Using this you can call different sidebars on different pages.

Syntax:

  • register_sidebar( $args )
  • get_sidebar(string $name = null)

Parameters:

ParameterDetails
$args(string | array) (Optional) Builds sidebar based on the name and id vvalues
$name*(string) (Optional) The name of the specialised sidebar. Default value: null

Contributors

Topic Id: 6293

Example Ids: 21749,25069

This site is not affiliated with any of the contributors.