• 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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Since you’re using widgets, the relevant ids and classes will be defined in your theme’s functions.php file.

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

    Has anyone found out why this is happening yet?

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

    lilqhgal

    (@lilqhgal)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP adding ‘-2’ to ID names in my Sidebar’ is closed to new replies.