get_sidebar
Action HookDescription
Fires before the sidebar template file is loaded.Hook Information
File Location |
wp-includes/general-template.php
View on GitHub
|
Hook Type | Action |
Line Number | 126 |
Hook Parameters
Type | Name | Description |
---|---|---|
string|null
|
$name
|
Name of the specific sidebar file to use. Null for the default sidebar. |
array
|
$args
|
Additional arguments passed to the sidebar template. |
Usage Examples
Basic Usage
<?php
// Hook into get_sidebar
add_action('get_sidebar', 'my_custom_function', 10, 2);
function my_custom_function($name, $args) {
// Your custom code here
}
Source Code Context
wp-includes/general-template.php:126
- How this hook is used in WordPress core
<?php
121 * @since 5.5.0 The `$args` parameter was added.
122 *
123 * @param string|null $name Name of the specific sidebar file to use. Null for the default sidebar.
124 * @param array $args Additional arguments passed to the sidebar template.
125 */
126 do_action( 'get_sidebar', $name, $args );
127
128 $templates = array();
129 $name = (string) $name;
130 if ( '' !== $name ) {
131 $templates[] = "sidebar-{$name}.php";
PHP Documentation
<?php
/**
* Fires before the sidebar template file is loaded.
*
* @since 2.2.0
* @since 2.8.0 The `$name` parameter was added.
* @since 5.5.0 The `$args` parameter was added.
*
* @param string|null $name Name of the specific sidebar file to use. Null for the default sidebar.
* @param array $args Additional arguments passed to the sidebar template.
*/
Quick Info
- Hook Type: Action
- Parameters: 2
- File: wp-includes/general-template.php
Related Hooks
Related hooks will be displayed here in future updates.