Support » Developing with WordPress » I am unable to display my new widget area

  • Resolved celinabrar

    (@celinabrar)


    Using a register widget area in the functions.php file of my (stunning )child theme, I can see a new widget and am able to add stuff to it. However, I have tried many commands to display that area and none of them work. While viewing any page in my site in the customizer it says “Your theme has 1 other widget area, but this particular page doesn’t display it.”
    I would like to display the widget in my header, next to the logo.

    The command I used:

    function stunning_child_widgets_init() {
        register_sidebar( array(
    		'name'          => 'Header',
    		'id'            => 'header_1',
    		'before_widget' => '<div>',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2 class="rounded">',
    		'after_title'   => '</h2>',
    	) );
    
    }
    add_action( 'widgets_init', 'stunning_child_widgets_init' );

    I have tried placing code into the header.php and index.php of my parent theme (they don’t exist in my child one) along with making the changes in functions in my child theme. Please help out.I can provide with exact code of files for reference if required.

    • This topic was modified 8 months ago by bcworkz. Reason: code fixed

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Sundar

    (@phptechie)

    Hi,

    Add this code in your sidebar.php file

    <?php if ( is_active_sidebar( 'header_1' ) ) : ?>
       <?php dynamic_sidebar( 'header_1' ); ?>
    <?php endif; ?>

    Thanks.

    • This reply was modified 8 months ago by bcworkz. Reason: code fixed
    Thread Starter celinabrar

    (@celinabrar)

    Thanks for your reply. Keeping aside the fact that I would like to display the widget in either my header or footer, my child theme does not have a sidebar.php file, unlike its adult theme. So shall I duplicate the file from the latter and add it, or would you suggest otherwise?

    • This reply was modified 8 months ago by celinabrar.
    Moderator bcworkz

    (@bcworkz)

    You can add Sundar’s code anywhere you want the widget area to appear, it does not need to be limited to sidebar.php.

    BTW, Sundar’s code initially had syntax errors because of the forum’s parser. It was not Sundar’s fault, it was this forum’s doing. I have since fixed their code to eliminate syntax errors.

    @phptechie – when you post code in these forums, please demarcate with backticks or use the code button, otherwise the people you so generously helped could have difficulty implementing your code.

    Thread Starter celinabrar

    (@celinabrar)

    @bcworkz I understand what you’re saying. The thing is like I mentioned before, my child theme does not have a sidebar.php/header.php/footer.php file, unlike its adult theme. So shall I duplicate the file from the latter and add it, or would you suggest otherwise? Also, I have tried this code before in the adult theme (as available on a WordPress article) and it still showed the same message. Sometimes, when I manipulated it position, it would just change the font of my logo but wouldn’t show any widgets.

    Moderator bcworkz

    (@bcworkz)

    Do you see a “Header” widget area on the widgets admin screen? And you’ve presumably added widgets there, right? Then calling dynamic_sidebar( 'header_1' ); on any template file used to fulfill the request should cause widgets to be output. They might display oddly due to no matching CSS, but you should at least get the widget HTML output and nothing about the page doesn’t display the widget area because that is exactly what dynamic_sidebar() does.

    FWIW, I placed your code in my own child theme’s functions.php and I placed Sundar’s code on a template file. I added a custom HTML widget that outputs “Hello world” as a test. Everything works as expected, so if you still have difficulty, it’s due to something beyond what we’ve discussed so far.

    Thread Starter celinabrar

    (@celinabrar)

    Ironically, no matter what I do I just can’t get to display any of the three active items in the widget area. The closest I ever got to doing so was when I placed the code in some file (i think it was the index) of the parent theme, and the whole logo of my site changed to plain text. It does come in the widgets admin screen but the customizer shows the error : Your theme has 1 other widget area, but this particular page doesn’t display it. This remains the same for every page.
    You can navigate to other pages on your site while using the Customizer to view and edit the widgets displayed on those pages. (This remains the same for every page.)
    I do not understand what the problem is. I wish I could somehow share my site’s files to show you. Is there any way you can get access to them?

    Moderator bcworkz

    (@bcworkz)

    Where did you place the dynamic_sidebar( 'header_1' ); call? Are you sure that template is actually being used on the page shown in the customizer? Try defining WP_DEBUG as true on wp-config.php. It could be some other syntax error is preventing dynamic_sidebar() from properly executing.

    What’s the source of your theme? If it’s an open source, non-commercial theme which you’ve modified, or a theme you’ve created yourself which you’re willing to publicly distribute, you could zip the theme files and upload to any of the file sharing services, or grant public access to the zip file on your Google drive. Provide the link here. Someone might be willing to download and test the files for themselves. Such an evaluation is a big ask for a volunteer forum, be prepared for a poor response. Still doesn’t hurt to try, provided the theme can be publicly distributed.

    Thread Starter celinabrar

    (@celinabrar)

    Thanks @bcworkz I was able to solve that problem. There is another issue I’ve been facing that I hope you could me with: https://wordpress.org/support/topic/some-post-images-appearing-blurry-after-using-blogger-importer/#new-topic-0.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘I am unable to display my new widget area’ is closed to new replies.