0

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:

enter image description here

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:

enter image description here

Why is the code showing at the top of the screen? What should I do differently here?

4
  • That does not look like an error, it seems to be simply printing the code you have added, so something - perhaps another plugins - is causing this issue, you might need to disable all other plugins / themes to try to resolve.
    – Q Studio
    Commented Jan 28, 2021 at 22:25
  • 1
    Is that your entire functions.php file? Or just what you added?
    – Tom J Nowell
    Commented Jan 28, 2021 at 23:15
  • @TomJNowell That's the entire functions.php file for the child theme, yes. Commented Jan 29, 2021 at 2:05
  • And you've confirmed this issue happens everywhere that you try to do this? Not just on your specific site or local setup? There is nothing in your functions.php that could do this, the problem is elsewhere
    – Tom J Nowell
    Commented Jan 30, 2021 at 14:18

1 Answer 1

0

For 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.com/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();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.