0

I tried to customize my WordPress theme but it shows this error.

Your theme has 2 widget areas, but this particular page doesn’t display them. You can navigate to other pages on your site while using the Customizer to view > and edit the widgets displayed on those pages.

First, there didn't show widget area so I Add this code for that then it shows widget and but now show the above error.

if (function_exists("register_sidebar")) {
register_sidebar();
}

This is my function.php file how can I solve this issue. Do I want to change any other page?

<?php

/**
 * Enqueues scripts and styles.
 *
 */
if (function_exists("register_sidebar")) {
register_sidebar();
}

function umk_enque_scripts() {

    wp_enqueue_style( 'normalize-style', get_template_directory_uri() . '/css/normal.css' );
    wp_enqueue_style( 'umkthemes-style', get_stylesheet_uri() );
    wp_enqueue_style( 'custom-css', get_template_directory_uri() . '/css/custom.css' );
    wp_enqueue_style( 'landmark', get_template_directory_uri() . '/css/landmark-map.css' );

    // wp_enqueue_script( 'umkthemes-script', get_template_directory_uri(). '/js/responsiveslides.min.js', array( 'jquery' ), '1.0' );  
}

add_action( 'wp_enqueue_scripts', 'umk_enque_scripts' );

function umkthemes_setup() {
    add_theme_support ('menus');
    add_theme_support( 'post-thumbnails' ); 
    // set_post_thumbnail_size( 273 , 146 );

    register_nav_menus( array(
        'primary_menu' => 'Main navigation',
    ) );
}

add_action( 'after_setup_theme', 'umkthemes_setup' );



// Our custom post type function
function create_posttype() {

     register_post_type( 'sale',
    // CPT Options
        array(
            'labels' => array(
                'name' => __( 'Sale' ),
                'singular_name' => __( 'Sale' ),
                'all_items' => __('All Sales', 'umkthemes'), /* the all items menu item */
                'add_new' => __('Add New Sale', 'umkthemes'), /* The add new menu item */
                'add_new_item' => __('Add New Sale', 'umkthemes'), /* Add New Display Title */
                'edit' => __( 'Edit', 'jointstheme' ), /* Edit Dialog */
                'edit_item' => __('Edit Sale', 'umkthemes'), /* Edit Display Title */
                'new_item' => __('New  Sale', 'umkthemes'), /* New Display Title */
                'view_item' => __('View Sale', 'umkthemes'), /* View Display Title */
                'search_items' => __('Search Sale', 'umkthemes'), /* Search Custom Type Title */
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'sale'),
            'supports' => array( 'title', 'editor', 'thumbnail', )
        )
    );
}




// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
3
  • This should be if(!function_exists("register_sidebar")) { /* Your Code */ }
    – Pim
    Sep 14, 2018 at 7:51
  • @Pim No it shouldn't. Why would that help? Sep 16, 2018 at 3:46
  • Considering that register_sidebar() has been a part of core since 2.2.0, really it's rather strange change to check for it's existence at all... @RUC... register_sidebar() creates a new area for widgets, but it does not display it. You'll need a call to dynamic_sidebar() for that.
    – bosco
    Sep 17, 2018 at 16:23

2 Answers 2

0

please Function.php file

function twentyseventeen_widgets_init() {   
    register_sidebar( array(
        'name'          => __( 'Blog Sidebar', 'twentyseventeen' ),
        'id'            => 'sidebar-1',
        'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );    
}
add_action( 'widgets_init', 'twentyseventeen_widgets_init' );

then after calling any template otherwise any files(header.php, footer.php etc)

also, add any widget in widget page in admin the name is 'Bolg sidebar'

0

Error: Your theme has 2 widget areas, but this particular page doesn’t display them. You can navigate to other pages on your site while using the Customizer to view > and edit the widgets displayed on those pages.

This is beacuse theme might be using conditional loading of widgets on particular pages i.e.,

if ( is_single() ) :
  get_sidebar( 'primary' );
endif;

And if you are in a page that doesn't support widgets, WordPress will display that message

Remove this code in your functions.php file

  if (function_exists("register_sidebar")) {
    register_sidebar();
    }

and include the file containing that function ( register_sidebar() )

like: require_once WP_CONTENT_DIR . '/includes/function-file.php';

Or you can register sidebar directly in your functions.php file like:

    add_action( 'widgets_init', 'my_register_sidebars' );
        function my_register_sidebars() {
        /* Register the 'primary' sidebar. */
            register_sidebar(
                array(
                    'id'            => 'primary',
                    'name'          => __( 'Primary Sidebar' ),
                    'description'   => __( 'A short description of the sidebar.' ),
                    'before_widget' => '<div id="%1$s" class="widget %2$s">',
                    'after_widget'  => '</div>',
                    'before_title'  => '<h3 class="widget-title">',
                    'after_title'   => '</h3>',
                )
            );
            /* Repeat register_sidebar() code for additional sidebars. */
        }

and to display sidebar in your theme template ( usually you'll need to create a sidebar.php file ) paste following code

<div id="sidebar-primary" class="sidebar">
    <?php if ( is_active_sidebar( 'primary' ) ) : ?>
        <?php dynamic_sidebar( 'primary' ); ?>
    <?php else : ?>
        <!-- Time to add some widgets! -->
    <?php endif; ?>
</div>

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.