Multiple declarations of sidebars in functions.php

I have an odd scenario. I’ve created three dynamic sidebars and trying to work out why some code I’d put in for styling wasn’t working. I’ve found them declared twice in the functions.php - all three and then all three again. What I put in in PG goes into the first ones but not the second so doesn’t appear in the site. How can I find why this is happening?

I am confused by what you are saying. You have two sets of styles that are identical in your functions.php file?

I don’t use Wordpress but the styles should be in the Theme section of Wordpress in CSS style sheets and not in PHP code. Unless they changed it since I last used it several years ago.

Remember that CSS works in precedence so what ever style comes last or on the bottom is what will change the look of the page.

a:hover( color: red; )
a:hover( color: orange; )
a:hover( color: green; )

In the above scenerio the text color for links that are hovered over will be Green.

Thanks for your response. It’s not the CSS which is the problem. In Pinegrow I’ve created three sidebars and edited the field ‘Before Title’ to include a CSS class. I’ve then put the styling for that class in my styles.css file.

However, what’s happening is the three sidebars are declared in the functions.php file, then declared again. But my custom html in the ‘Before Title’ field is only outputting in the first set. The second set then recreate the sidebars without my CSS class so I lose the styling.

It took me a while to find why the CSS wasn’t showing. I spotted the class wasn’t output and then looked through the functions.php file to spot the duplication.

Here’s what is in my functions.php file:

/*
 * Register widget areas.
 */
/* Pinegrow generated Register Sidebars Begin */

register_sidebar( array(
    'name' => __( 'Footer Col 1', 'lifestreams' ),
    'id' => 'footer_col_1',
    'description' => 'Footer Column 1',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h3 class="widgettitle footer-widget-title">',
    'after_title' => '</h3>'
) );

register_sidebar( array(
    'name' => __( 'Footer Col 2', 'lifestreams' ),
    'id' => 'footer_col_2',
    'description' => 'Footer Column 2',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h3 class="widgettitle footer-widget-title">',
    'after_title' => '</h3>'
) );

register_sidebar( array(
    'name' => __( 'Footer Col 3', 'lifestreams' ),
    'id' => 'footer_col_3',
    'description' => 'Footer Column 3',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h3 class="widgettitle footer-widget-title">',
    'after_title' => '</h3>'
) );

register_sidebar( array(
    'name' => __( 'Footer Col 1', 'lifestreams' ),
    'id' => 'footer_col_1',
    'description' => 'Footer Column 1',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
) );

register_sidebar( array(
    'name' => __( 'Footer Col 2', 'lifestreams' ),
    'id' => 'footer_col_2',
    'description' => 'Footer Column 2',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
) );

register_sidebar( array(
    'name' => __( 'Footer Col 3', 'lifestreams' ),
    'id' => 'footer_col_3',
    'description' => 'Footer Column 3',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>'
) );

/* Pinegrow generated Register Sidebars End */

Hope this clarifies it. Any idea what’s causing it?

Delete the second set from the functions.php file. The “%2$s” stuff is breaking wordpress.

I would say this is a bug in Pinegrow some where. Though I am NOT a wordpress user and don’t use the WP version of Pinegrow. The site should work again when you make those changes, if not then I have no idea,

Thanks for that. Yep, I’ve already removed the second set manually and everything is good. But when I re-export the theme, it all appears again. So I really need to get it sorted.

The %2$s stuff isn’t actually in my functions.php file. I think that appeared when copying/pasting to this forum. They are proper, clean class names in there.

Definitely sounds like a bug. Hopefully easily fixed.

Can you detail what you did creating the three dynamic tool bars of yours? There maybe something in the way you did something there that could be causing it though someone else would need to help you that has the Wordpress version of Pinegrow. Something is telling PG to create that second set. Could be an additional comma or something similar that shouldn’t be there or unclosed paran’s or similar.

Edit, didn’t catch that the Forum altered the copy / pasting above. Edited to correct.

I think it must be a bug. I didn’t do anything unusual. And it’s specific to the WP edition.

Thanks for your help, though.

Quick tip: The best way to define “configuration elements” like sidebars, custom post types and more is to use a settings page as described here: http://docs.pinegrow.com/wordpress-themes/why-and-how-to-create-a-settings-page

and … from my experience, most of the issues come from duplicate settings. (copy paste from template to template and so on).

Please, send your project folder (ZIP file) and support request to support@pinegrow.com and we will have a look at it.

1 Like

Wow, that’s a really good and important tip. I think I know what the problem is now. I’ve been putting the sidebar actions in the footer and recently added a second page to the theme. I’ll now remove them from those pages and create a functions.html page and put them in there instead. I’ll let you know how it goes.

Thanks for that.

SORTED! That was the problem. I will now create a functions.html file for all new projects. It’s a much tidier way of working, too.

Quick follow up question… can I use that file to put any custom PHP which I would want in the functions.php file?

Thanks again.

hey,

i got the same problem with my site. i got some more child themes and every child theme loads the sidebars from the footer after applying the master page to all child themes.

I am not understanding your solution. How can i fix this?

Best wishes,
Mike

When stuff are repeated twice in functions.php after an export the only reason is that there is a duplicate WP action somewhere in 2 or more templates.

Duplicates WP actions appears when you duplicate templates so you can reuse them for another need but you forget to remove WP actions which have an impact on functions.php (custom post types, sidebars and more …)

@MikeM : @sitestreet is talking about this http://docs.pinegrow.com/why-and-how-to-create-a-settings-page/

1 Like