0
votes

Custom theme is throwing a php error on display. The error says to set sidebar id but not sure how to set it. Error: "register_sidebar was called incorrectly. No id was set in the arguments array for the "My Sidebar" sidebar. Defaulting to "sidebar-1". Manually set the id to "sidebar-1" to silence this notice and keep existing sidebar content."

I have tried removing the custom theme and replacing it.

Here is theme function sidebar.php:

 <div class="span4 ">
            <!-- *** SIDEBAR START *** -->
     <aside class="sidebar">
        <div class="widget categories">
          <?php   /* Widgetized sidebar, if you have the plugin installed. */
           if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
           <?php wp_list_categories('title_li=Cat'); ?>
           <?php the_tags(); ?>
          <?php endif; ?>
        </div><!-- end categories -->
    </aside><!--end sidebar-->
  <!-- *** SIDEBAR END *** -->

  </div>

Thinking it might be done here in /wp-includes/widgets.php which has fn: register_sidebars

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);
    }
}

Here is register_sidebar function from widgets.php:

function register_sidebar($args = array()) {
    global $wp_registered_sidebars;

    $i = count($wp_registered_sidebars) + 1;

    $id_is_empty = empty( $args['id'] );

    $defaults = array(
        'name' => sprintf(__('Sidebar %d'), $i ),
        'id' => "sidebar-$i",
        'description' => '',
        'class' => '',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => "</li>\n",
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => "</h2>\n",
    );

    $sidebar = wp_parse_args( $args, $defaults );

    if ( $id_is_empty ) {
        /* translators: 1: the id argument, 2: sidebar name, 3: recommended id value */
        _doing_it_wrong( __FUNCTION__, sprintf( __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.' ), '<code>id</code>', $sidebar['name'], $sidebar['id'] ), '4.2.0' );
    }

    $wp_registered_sidebars[$sidebar['id']] = $sidebar;

    add_theme_support('widgets');

    /**
     * Fires once a sidebar has been registered.
     *
     * @since 3.0.0
     *
     * @param array $sidebar Parsed arguments for the registered sidebar.
     */
    do_action( 'register_sidebar', $sidebar );

    return $sidebar['id'];
}
2
So you need to remove the sidebar or set the id?Ivnhal
I'm looking to set the id. I tried a couple things within this code but it didn't alter the error.PatrickLightning
Can you post the code of register_sidebar function in your question?Ivnhal
Yes it's added now.PatrickLightning

2 Answers

0
votes

Change line:

function register_sidebar($args = array()) {

to:

function register_sidebars($args = array()) {
0
votes
function register_sidebar($args = array()) {

to:

function register_sidebars($args = array()) {

That works for me.