Create new widget sidebar?
-
Using a child theme, how can I create a new sidebar with widget area so that it shows up to the below navigation and to the right of my content?
I only want this on my main page, if possible.
My modified style file is here: https://www.tf2tightrope.com/wp-content/themes/bouquet-child/style.css
My website is tf2tightrope.com
Any help is much appreciated. Thanks.
-
Hi @cooljosh3k,
You can find some guidance for creating a new widget area for your theme here:
https://codex.www.ads-software.com/Widgetizing_Themes
The above guidance also links to this handy resource, which will generate some of the code needed on your behalf:
https://generatewp.com/sidebar/
The steps involved with setting up a new widget area will require you to experiment with PHP, CSS, and HTML. Specific step-by-step instructions and code goes beyond the scope of support this intended for but, if you take a look through the guidance provided, I’ll be happy to help point you in the right direction if questions come up.
Thanks. I added the example from generatewp so my functions.php now looks like this:
<?php add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); // Register Sidebars function custom_sidebar() { $args = array( 'id' => 'sidebar-aside', 'name' => __( 'Secondary Widget Area', 'text_domain' ), 'description' => __( 'Aside Widgets.', 'text_domain' ), 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', ); register_sidebar( $args ); } add_action( 'widgets_init', 'custom_sidebar' ); }
However when I go to customize, I can still only see the original “Sidebar 1”.
Hi @cooljosh3k,
It looks like you copied the code for the sidebar before the last curly bracket – } – in your child theme’s functions.php file. The code should actually be copied after that bracket:
<?php add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } // Register Sidebars function custom_sidebar() { $args = array( 'id' => 'sidebar-aside', 'name' => __( 'Secondary Widget Area', 'text_domain' ), 'description' => __( 'Aside Widgets.', 'text_domain' ), 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', ); register_sidebar( $args ); } add_action( 'widgets_init', 'custom_sidebar' );
Hope that helps out!
Dang, I thought I was clever in thinking it had to go that way.
Fixed it up, but going to https://www.tf2tightrope.com/wp-content/themes/bouquet-child/functions.php gives me the error:
Fatal error: Call to undefined function add_action() in /home/tftightr/public_html/wp-content/themes/bouquet-child/functions.php on line 2
Hi @cooljosh3k,
I’m unsure why that error is appearing and haven’t been able to replicate on my own set up. One suggestion is to try the complete and recommended functions.php snippet from the Codex page in place of what you already have:
<?php function my_theme_enqueue_styles() { $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme. wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
I have tried changing it to that which you suggested. Still getting that same result.
<?php add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } // Register Sidebars function custom_sidebar() { $args = array( 'id' => 'sidebar-aside', 'name' => __( 'Secondary Widget Area', 'text_domain' ), 'description' => __( 'Aside Widgets.', 'text_domain' ), 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', ); register_sidebar( $args ); } add_action( 'widgets_init', 'custom_sidebar' );
I presume it is something about that “add_action” part.
Digging in some research, it seems the issue is becuase the add_action function is not included.
Still trying to figure out how to do this.
Okay, so in simple terms as far as I can understand…
<?php function my_theme_enqueue_styles() { $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme. wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); // Register Sidebars function custom_sidebar() { $args = array( 'id' => 'sidebar-aside', 'name' => __( 'Secondary Widget Area', 'text_domain' ), 'description' => __( 'Aside Widgets.', 'text_domain' ), 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', ); register_sidebar( $args ); } add_action( 'widgets_init', 'custom_sidebar' );
How can I make it so that the add_action is included for use in a child theme’s function file?
Hi @cooljosh3k,
I haven’t been able to replicate the error that you’re seeing but suggest the following two troubleshooting steps:
- Double check that your functions.php file does not end with a closing }. If it does, remove it and see if that resolves the error.
- Disable your plugins one by one and check to see if the error remains each time. A plugin may be conflicting with some of the theme’s code.
I have disabled each plugin one by one, but nothing changed. I made sure to purge my cache via CloudFlare for each time.
In hope to find an answer, I have opened a support ticket with my web hosting provider (GreenGeeks).
I noticed this same error is shown when I try to view the https://www.tf2tightrope.com/wp-content/themes/bouquet/functions.php as well as where if first noticed it (https://www.tf2tightrope.com/wp-content/themes/bouquet-child/functions.php).
So far with research I have seen people recommending the use of loading wp-load.php, but plenty to advice that doing this is wrong.
Could you try uninstalling/deleting your current copy of Bouquet and then installing a completely fresh copy?
Tried a fresh install of TwentySixten and found the following error for https://www.tf2tightrope.com/wp-content/themes/twentysixteen/functions.php
Fatal error: Call to undefined function get_template_directory() in /home/tftightr/public_html/wp-content/themes/twentysixteen/functions.php on line 32
Fresh install of Bouquet gives that same error again. This is without running the child theme.
Hosting Provider was not much use. They said all they could do was tweak PHP settings if I need.
Come to think of it, I am not seeing these errors just because I am viewing the files directly via a browser, am I?
Come to think of it, I am not seeing these errors just because I am viewing the files directly via a browser, am I?
This might be what’s happening, although it’s not something I’ve come across before.
The function itself is bringing in Bouquet’s parent theme’s style.css file to the child theme. From viewing your site with the active child theme, you can see that the function is working as intended.
Okay,
Even with this, I cannot see the new sidebar in customise.
- The topic ‘Create new widget sidebar?’ is closed to new replies.