-
AuthorPosts
-
February 22, 2015 at 3:17 pm #400210
HI,
I want to have a second sidebar Pages widget, so I can add another menu to certain pages.
I now have three menus, one on top and one in use for the ‘food’ page.
I want another menu driving the ‘wine’ page, so I need another Sidebar Page widget to choose in the page options.What I now did is added one in the register-widget-area.php file, and that works as expected.
Add additional menu to second Page widget, open a page, set a sidebar, select second new widget for sidebar,and presto!But I rather not change the theme files, and would like to add this in my child theme. How can I ‘transport’ the code for the Sidebar Page widget (line 29-38) to the child theme, so it won’t break after a Enfold update.
cheers!
rob
February 23, 2015 at 6:17 pm #400878Hey RobWu!
What is the code you used?
Regards,
ElliottFebruary 23, 2015 at 6:47 pm #400910Hi Elliot,
What I did is copy the original code back into the php file, but renamed the widget. Very basic, but working. So now I have:
foreach ($sidebars_to_show as $sidebar)
{
register_sidebar(array(
‘name’ => ‘Sidebar Pages’,
‘before_widget’ => ‘<section id=”%1$s” class=”widget clearfix %2$s”>’,
‘after_widget’ => ‘<span class=”seperator extralight-border”></span></section>’,
‘before_title’ => ‘<h3 class=”widgettitle”>’,
‘after_title’ => ‘</h3>’,
));
}foreach ($sidebars_to_show as $sidebar)
{
register_sidebar(array(
‘name’ => ‘Sidebar Pages2’,
‘before_widget’ => ‘<section id=”%1$s” class=”widget clearfix %2$s”>’,
‘after_widget’ => ‘<span class=”seperator extralight-border”></span></section>’,
‘before_title’ => ‘<h3 class=”widgettitle”>’,
‘after_title’ => ‘</h3>’,
));
}As I said, I feel better to have the second widget bar into my child theme.
rob
February 24, 2015 at 1:07 pm #401364Hey!
If I am not mistaken, you can just add it directly to the child theme’s functions.php:
register_sidebar(array( 'name' => 'Sidebar Blog 2', 'before_widget' => '<section id="%1$s" class="widget clearfix %2$s">', 'after_widget' => '<span class="seperator extralight-border"></span></section>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>', ));
Best regards,
IsmaelFebruary 24, 2015 at 1:23 pm #401378Hi Ismael,
Thanks for the reply, but if I move the additional code to my child theme’s functions.php it doesn’t work.
I’ll loose the second widget in the WordPress Widget section.The addition of the code to the functions.php doesn’t break the php, so there’s some small thing not working I guess.
rob
February 25, 2015 at 7:07 am #401872Hi!
I tested this code on functions.php and it adds the custom widget area called Sidebar Blog 2. If you’re worried about losing the existing widgets, rename the widget area then transfer the widgets to the newly created sidebar.
Regards,
IsmaelFebruary 25, 2015 at 10:45 am #401944Hi Ismael,
I did some testing. For starters, I emptied my child theme’s functions.php file and added just the code above. No second widget in WP.
Than I turned off all plugins but the basic Woocommerce, and I get the following error on the top of the site:
‘Warning: Invalid argument supplied for foreach() in V:\xampp\htdocs\cavador\cavabin\wp-content\themes\enfold-child\functions.php on line 10″Line 10 here is: foreach ($sidebars_to_show as $sidebar)
so that first line of code is rejected by the child theme.
So close… ;-)
rob
February 27, 2015 at 10:45 am #403291Any thoughts??
I cannot get it to work for the site. Even with all plugins deactivated and an empty functions.php in the child theme.
The php doesn’t break and the site works, but I don’t get another widget on the widget page.
I do when I add the same code in the theme itself as described above.So I hereby want to request a second Sidebar Pages for the next update. I cannot be the only one who wants this.
I feel very uncomfortable changing code in the theme itself, due to future updates and breaking functionality.
Child themes are perfect for these reasons, and give you a more logical overview of what has been added or changed.rob
February 27, 2015 at 10:52 am #403296Hi!
Replace it with this:
register_sidebar(array( 'name' => 'Sidebar Blog 2', 'before_widget' => '<section id="%1$s" class="widget clearfix %2$s">', 'after_widget' => '<span class="seperator extralight-border"></span></section>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>', )); register_sidebar(array( 'name' => 'Awesome Sidebar', 'before_widget' => '<section id="%1$s" class="widget clearfix %2$s">', 'after_widget' => '<span class="seperator extralight-border"></span></section>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>', ));
Regards,
IsmaelFebruary 27, 2015 at 11:07 am #403304Looking at the code I cannot see any differences, but for some reason this now works! For both widget additions.
No idea who/why/what… ;-)I did make an official request for at least one additional Sidebar Widget on the forum, I hope it will emerge some day.
Thanks for all the help, much appreciated!!
rob
February 28, 2015 at 12:38 pm #403821 -
AuthorPosts
- The topic ‘Second Sidebar Pages Question – moving code to child theme’ is closed to new replies.