I'm using the very popular Elementor theme to build my WordPress site, but unfortunately there is not a Widgets option when I go to Appearance in the Dashboard:
I need it in order to create a sidebar.
So this has caused me to install a Child Theme, so that I can add some code to functions.php
in order to get the widgets option to show.
This is what I have in my functions.php
file for the child theme:
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
add_action('widgets_init', 'outWidgetsInit');
function ourWidgetsInit() {
register_sidebar( array (
'name' => 'Sidebar',
'id' => 'sidebar1',
));
}
And this is causing errors to show at the top of the theme while developing:
Why is the code showing at the top of the screen? What should I do differently here?
I'm using the very popular Elementor theme to build my WordPress site, but unfortunately there is not a Widgets option when I go to Appearance in the Dashboard:
I need it in order to create a sidebar.
So this has caused me to install a Child Theme, so that I can add some code to functions.php
in order to get the widgets option to show.
This is what I have in my functions.php
file for the child theme:
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
add_action('widgets_init', 'outWidgetsInit');
function ourWidgetsInit() {
register_sidebar( array (
'name' => 'Sidebar',
'id' => 'sidebar1',
));
}
And this is causing errors to show at the top of the theme while developing:
Why is the code showing at the top of the screen? What should I do differently here?
Share Improve this question asked Jan 28, 2021 at 21:47 HappyHands31HappyHands31 13510 bronze badges 4 |1 Answer
Reset to default 0For whatever reason, maybe it was caching-related, but waiting a day and then adding this code at the bottom of functions.php
solved the issue:
if (function_exists("register_sidebar")) {
register_sidebar();
}
According to this article - see the 'How do I add the Widgets menu option'
https://elementor/help/hello-theme-tips/
So then the full code for my functions.php
file within the child theme is:
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
add_action('widgets_init', 'outWidgetsInit');
function ourWidgetsInit() {
register_sidebar( array (
'name' => 'Sidebar',
'id' => 'sidebar1',
));
}
if (function_exists("register_sidebar")) {
register_sidebar();
}
functions.php
file? Or just what you added? – Tom J Nowell ♦ Commented Jan 28, 2021 at 23:15functions.php
file for the child theme, yes. – HappyHands31 Commented Jan 29, 2021 at 2:05functions.php
that could do this, the problem is elsewhere – Tom J Nowell ♦ Commented Jan 30, 2021 at 14:18