admin管理员组

文章数量:1333181

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';
   
} ?>

本文标签: Sidebar not displaying (theme development)