register_sidebars

The timeline below displays how wordpress function register_sidebars has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @global array $wp_registered_sidebars The new sidebars are stored in this array by sidebar ID.
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the ID will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            if (isset($args['name'])) {
                $_args['name'] = sprintf($args['name'], $i);
            } else {
                /* translators: %d: Sidebar number. */
                $_args['name'] = sprintf(__('Sidebar %d'), $i);
            }
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        /*
         * Custom specified ID's are suffixed if they exist already.
         * Automatically generated sidebar names need to be suffixed regardless starting at -0.
         */
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom IDs.
            while (is_registered_sidebar($_args['id'])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (is_registered_sidebar($_args['id']));
        }
        register_sidebar($_args);
    }
}

WordPress Version: 5.5

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @global array $wp_registered_sidebars The new sidebars are stored in this array by sidebar ID.
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the ID will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            if (isset($args['name'])) {
                $_args['name'] = sprintf($args['name'], $i);
            } else {
                /* translators: %d: Sidebar number. */
                $_args['name'] = sprintf(__('Sidebar %d'), $i);
            }
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0.
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom IDs.
            while (is_registered_sidebar($_args['id'])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (is_registered_sidebar($_args['id']));
        }
        register_sidebar($_args);
    }
}

WordPress Version: 5.4

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @global array $wp_registered_sidebars The new sidebars are stored in this array by sidebar ID.
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the id will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            if (isset($args['name'])) {
                $_args['name'] = sprintf($args['name'], $i);
            } else {
                /* translators: %d: Sidebar number. */
                $_args['name'] = sprintf(__('Sidebar %d'), $i);
            }
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0.
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom IDs.
            while (is_registered_sidebar($_args['id'])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (is_registered_sidebar($_args['id']));
        }
        register_sidebar($_args);
    }
}

WordPress Version: 5.3

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @global array $wp_registered_sidebars The new sidebars are stored in this array by sidebar ID.
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the id will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            if (isset($args['name'])) {
                $_args['name'] = sprintf($args['name'], $i);
            } else {
                /* translators: %d: Sidebar number. */
                $_args['name'] = sprintf(__('Sidebar %d'), $i);
            }
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom ID's
            while (is_registered_sidebar($_args['id'])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (is_registered_sidebar($_args['id']));
        }
        register_sidebar($_args);
    }
}

WordPress Version: 5.1

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @global array $wp_registered_sidebars The new sidebars are stored in this array by sidebar ID.
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the id will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom ID's
            while (is_registered_sidebar($_args['id'])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (is_registered_sidebar($_args['id']));
        }
        register_sidebar($_args);
    }
}

WordPress Version: 4.4

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @global array $wp_registered_sidebars
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the id will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom ID's
            while (is_registered_sidebar($_args['id'])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (is_registered_sidebar($_args['id']));
        }
        register_sidebar($_args);
    }
}

WordPress Version: 4.3

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @global array $wp_registered_sidebars
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the id will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom ID's
            while (isset($wp_registered_sidebars[$_args['id']])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (isset($wp_registered_sidebars[$_args['id']]));
        }
        register_sidebar($_args);
    }
}

WordPress Version: 4.1

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the id will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom ID's
            while (isset($wp_registered_sidebars[$_args['id']])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (isset($wp_registered_sidebars[$_args['id']]));
        }
        register_sidebar($_args);
    }
}

WordPress Version: 3.7

/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in $args, then they will be built for you.
 *
 * The default for the name is "Sidebar #", with '#' being replaced with the
 * number the sidebar is currently when greater than one. If first sidebar, the
 * name will be just "Sidebar". The default for id is "sidebar-" followed by the
 * number the sidebar creation is currently at. If the id is provided, and multiple
 * sidebars are being defined, the id will have "-2" appended, and so on.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 * @uses parse_str() Converts a string to an array to be used in the rest of the function.
 * @uses register_sidebar() Sends single sidebar information [name, id] to this
 *	function to handle building the sidebar.
 *
 * @param int $number Number of sidebars to create.
 * @param string|array $args Builds Sidebar based off of 'name' and 'id' values.
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom ID's
            while (isset($wp_registered_sidebars[$_args['id']])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (isset($wp_registered_sidebars[$_args['id']]));
        }
        register_sidebar($_args);
    }
}