WordPress.org

Ready to get started?Download WordPress

Forums

WP adding '-2' to ID names in my Sidebar (6 posts)

  1. larrychartier
    Member
    Posted 4 years ago #

    Hoping someone can help me with this...

    For some reason WP is adding '-2' to my some of my sidebar ID's. Here is one example...It should read:

    '<li id="search" class="widget widget_search">'

    Somewhere along the way it changed to:

    '<li id="search-2" class="widget widget_search">'

    I'm not exactly sure why it is doing this as I haven't touched anything in the sidebar code. If anyone has any ideas or solutions to stop this from happening I would really appreciate it.

    Thanks in advance!

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Since you're using widgets, the relevant ids and classes will be defined in your theme's functions.php file.

  3. craigwann
    Member
    Posted 4 years ago #

    Same issue. Worpress is adding an extra "-2" to my search tag, giving me id="search-2". I have checked my functions.php file, but I am unable to find a solution.

    This first happened after I updated to 2.8. I was not having this issue before the update.

    @larrychartier - As a temporary fix, you might try changing the "#sidebar #search" style in your css file to "#sidebar #search-2". That's what I did.

    This is driving me nuts!

    Here is the search portion of my functions.php file.

    // Widget: Search; to match the theme style and replace Widget plugin default
    function widget_sandbox_search($args) {
    	extract($args);
    	$options = get_option('widget_sandbox_search');
    	$title = empty($options['title']) ? __( '', 'sandbox' ) : $options['title'];
    	$button = empty($options['button']) ? __( 'search', 'sandbox' ) : $options['button'];
    ?>
    			<?php echo $before_widget ?>
    				<form id="mainsearch" method="get" action="<?php bloginfo('home') ?>">
    	<div>
    		<input id="s" class="text-input" name="s" type="text" value="looking for something?" onfocus="if (this.value == 'looking for something?') {this.value = '';}" onblur="if (this.value == '') {this.value = 'looking for something?';}"  tabindex="1" />
    		<input id="searchsubmit" name="searchsubmit" type="image" src="<?php bloginfo('template_directory'); ?>/imgs/btn-search.gif" alt="search" tabindex="2" />
    	</div>
    </form>
    			<?php echo $after_widget ?>
    <?php
    }

    AND

    // Finished intializing Widgets plugin, now let's load the Sandbox default widgets; first, Sandbox search widget
    	$widget_ops = array(
    		'classname'    =>  'widget_pages',
    		'description'  =>  __( "Your blog's WordPress Pages (Autumn Forest)", "sandbox" )
    	);
    	wp_register_sidebar_widget( 'pages', __( 'Pages', 'sandbox' ), 'widget_sandbox_pages', $widget_ops );
    	unregister_widget_control('pages');
    	wp_register_widget_control( 'pages', __( 'Pages', 'sandbox' ), 'widget_sandbox_pages_control' );
    
    	$widget_ops = array(
    		'classname'    =>  'widget_search',
    		'description'  =>  __( "A search form for your blog (Autumn Forest)", "sandbox" )
    	);
    	wp_register_sidebar_widget( 'search', __( 'Search', 'sandbox' ), 'widget_sandbox_search', $widget_ops );
  4. shoshanna
    Member
    Posted 4 years ago #

    Has anyone found out why this is happening yet?

  5. konspire
    Member
    Posted 4 years ago #

    Just realized I am dealing with the same problem. What seems to be the cause of this?

  6. lilqhgal
    Member
    Posted 4 years ago #

    Do not look for the search stuff, look again in your functions file for something regarding the sidebars. It should look something like this:

    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'name' => __('Sidebar'),
            'before_widget' => '<div id="%1$s" class="sidebar_box">',
            'after_widget' => '</div><!--/widget-->',
            'before_title' => '<h3>',
            'after_title' => '</h3>',
        ));

    Note the id="%1$s" - that tells wordpress that if you have more than one widget of the same (such as 2 searches or 3 text widgets) to add an number to the div id. What confuses people is when they are playing around, add some stuff, then delete it, so you might only actually HAVE 1 search widget in use, but the code stays at #2, thus adding the 2 to the div id. Hope that helps.

Topic Closed

This topic has been closed to new replies.

About this Topic