0

I'm developing a theme via an online course and I can't get the sidebar to display.

I've used the hook widget_init and the function is being called because I can echo text out. Index.php is correctly able to read from sidebar.php because I can echo lines of code from there.

The problem seems to be that when I drag and drop widgets on the dashboard it's not saving them so my sidebar is always displaying as empty/false. It does show that it's saved but if I leave that area of the dashboard and go back to it everything has reset and I'm left with an empty sidebar.

Running the code below I get 'side bar not active' (from my echo) Any help would be appreciated.

//functions.php

include(get_theme_file_path( '/includes/widgets.php' ));

//widgets.php

<?php 
function JU_widgets(){
    echo 'Test JU_WIDGET Function';
    register_sidebar( [
        'name' => __('My First Theme Sidebar', 'udemy'),
        'id' => 'MM_sidebar',
        'description' => __('Udemy widget example', 'udemy')
    ] );
} ?>
//sidebar.php

<?php if( is_active_sidebar( 'MM_sidebar' ) ){
    echo 'sidebar active';
    
    dynamic_sidebar( 'MM_sidebar' ); 
}else{
  echo 'side bar not active';
   
} ?>
2
  • Could you please show the widget registration code? Meaning the add_action() call that hooks in JU_widgets()?
    – Fränk
    Jul 7 '20 at 14:16
  • Hi, thanks for your reply. I eventually managed to find the problem, there was some issue with the name, maybe it starting with double caps. I changed the name of the function and the name of the side bar and its working again now. At first I thought maybe I'd mistyped something but I was able to echo out from the function so it was obviously being called, mysterious. Jul 8 '20 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.