Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the PHP functions used to create and get sidebars in WordPress

Shulou Source: shulou.com Published: 2022-06-03 19:40:36 11月12日 Update

Editor to share with you WordPress used to create and obtain the sidebar of the PHP functions, I believe most people do not know much, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Register_sidebar () (create sidebar)

Create a sidebar to place gadgets. When using this function, please put it in a function and mount it to the "widgets_init" hook.

Usage

Register_sidebar ($args)

Parameters.

$args

(string | Array) (optional) the parameters of the sidebar to create.

Default value:

$args = array ('name' = > _ (' Sidebar name', 'theme_text_domain'),' id' = > 'unique-sidebar-id',' description' = >'', 'class' = >', 'before_widget' = >', 'after_widget' = >', 'before_title' = >', 'after_title' = >')

Array parameters introduction:

Name: sidebar name

Id: sidebar ID, which must be lowercase. Default is incremental array ID.

Description: sidebar description

Class: extra class for gadgets

Before_widget: the Html code at the beginning of the gadget inside

After_widget: the Html code at the end of the gadget inside

Before_title: the beginning Html code of the title of the gadget inside

After_title: the Html code at the end of the title of the gadget inside

Examples

Register_sidebar (array ('name' = > _ (' right sidebar'), 'id' = >' sidebar-1', 'description' = > _ _' right sidebar gadget. ), 'before_title' = >'', 'after_title' = >',))

Other

This function is located at: wp-includes/widgets.php

Get_sidebar () (get sidebar)

Get_sidebar () is used to introduce a sidebar template. If the name is specified, the sidebar- {name} .php file of the root directory of the current theme is introduced, the sidebar.php file of the root directory of the current theme is introduced if not specified, and the wp-includes/theme-compat/sidebar.php file is introduced if the file does not exist.

Usage

Get_sidebar ($name)

Parameters.

$name

(string) (optional) introduces the name of the template or, if specified, the sidebar- {$name} .php file of the root directory of the current theme.

Default value: None

Examples

The following code introduces the sidebar.php file of the root directory of the current topic:

The following code introduces the sidebar-left.php file of the root directory of the current topic:

The following example introduces the left sidebar (sidebar-left.php) and the right sidebar (sidebar-right.php), respectively:

Content and content

Other

This function is located at: wp-includes/general-template.php

This is all of the article "what are the PHP functions used to create and get sidebars in WordPress?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Side tool file function code topic root directory content parameter example name array article right character string rule beginning end title Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information Apple Microsoft Linux