Add header widget

How can I add a header widget to this theme. All the instructions I’ve found is to add this to the functions.php file:
<?php
/**

  • Register our sidebars and widgetized areas.

*/
function arphabet_widgets_init() {

register_sidebar( array(
	'name'          =&gt; 'Home right sidebar',
	'id'            =&gt; 'home_right_1',
	'before_widget' =&gt; '&lt;div&gt;',
	'after_widget'  =&gt; '&lt;/div&gt;',
	'before_title'  =&gt; '&lt;h2 class="rounded"&gt;',
	'after_title'   =&gt; '&lt;/h2&gt;',
) );

}
add_action( ‘widgets_init’, ‘arphabet_widgets_init’ );
?>

but that doesn’t seem to be the file where widgets are registered.

And then add:
<?php if ( is_active_sidebar( ‘home_right_1’ ) ) : ?>
<div id=“primary-sidebar” class=“primary-sidebar widget-area” role=“complementary”>
<?php dynamic_sidebar( ‘home_right_1’ ); ?>
</div><!-- #primary-sidebar
<?php endif; ?>

Can you please advise is this is correct and if so, which files and where in the files the code should go.
Thank you!

Hi @limoden,

I hope you are well today and thank you for your question.

Yes it’s correct.

To achieve this first you should create a child theme of Dazzling theme as described on the following page.

http://freewptp.com/tutorials/why-and-how-to-create-and-use-wordpress-child-theme/

Then add the following code in the functions.php file of it.

/**
* Register our sidebars and widgetized areas.
*
*/
function arphabet_widgets_init() {

register_sidebar( array(
'name' => 'Home right sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>'
) );

}
add_action( 'widgets_init', 'arphabet_widgets_init' );
?>

It will display the widget area “Home right sidebar” in your site widgets screen so just add the widgets in this newly created widget area.

Now you have to display this widget area in the header of your site so just copy the header.php file from the dazzling theme in to your child theme directory and then add the following code in this copied header.php file where you want to display the widgets.

<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="header-sidebar" class="header-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div><!– #primary-sidebar –>
<?php endif; ?>

Best Regards,
Movin

I have been looking for specific dazzling instructions on how to do this for weeks and here it is! Yay!

I tried to add the fist section of code to my Dazzling child theme’s functions.php. but it breaks my site. I realized Movin had left out the <?php open tag part of the code from the initial post. I added it completely using the code in the initial question and that is when it broke my site. Is there something wrong with my child theme? Wrong with this verison of code?

There was code there there from a previous administrator (with <?php open and close tags) and it did create an sidebar-2 area fine and I could insert widgets into it on in the apperance>widget part of the dashboard but the sidebar/widgets didn’t appear on any pages even when there were widgets in place. It wasn’t completed somewhere.

I tried to copy the extra sidebard code and add a make minor title adjustments for a header area. I then added calling code to the header.php file for my child theme. It didn’t break the site but the widget didn’t appear at all. Just like the original sidebar-2 code was acting (failing).

I see that there is a kind of template file called sidebar and sidebar-footer. Should one of those be modified to see this header widget area that I am trying to make in the functions.php? This is never mentioned in any help i can find online.

I have seen lots of versions of this code to insert a sidebar.
The best instructions that I have found (but which are not specific to Dazzling theme) are here:

Here is the code I was going to use. Why is it different from this set? My site is live and handling traffic, tho. I want to be sure this is correct before I go making a big change like this.

Here is the code I have for the Function.php Does this look Correct?>

<?php

  • Register new widget areas.
    */
    function register_widget_areas() {
    register_sidebar( array(
    ‘name’ => __( ’ Header Widget Area’, ‘dazzing-child’ ),
    ‘id’ =>‘header-1’,
    ‘description’ => __( ‘Add widgets here to appear in your header.’, ‘dazzling-child’ ),
    ‘before_widget’ => ‘<aside id="%1$s" class=“widget %2$s”>’,
    ‘after_widget’ => ‘</aside>’,
    ‘before_title’ => ‘<h2 class=“header-widget”>’,
    ‘after_title’ => ‘</h2>’,
    ) );
    }
    add_action( ‘widgets_init’, ‘register_widget_areas’ );
    ;
    ?>

Then in the header.php right after the nav-bar section I should insert the following. I put it into <div> container so that I would use CSS to size it and float it right.

<div class=“header-widget-area”>
<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘header-1’) ) : ?>
<?php endif; ?>
</div>

I don’t understand why this code is different from Movin’s. Which one will work? I feel like I am close… but am still stumbling around in the dark. I would really like some advice from someone who understands this stuff.

@lisap To help us keep support thread separates could you please create your own thread for your question here https://colorlibsupport.com/c/dazzling/ instead of replying on others thread as it makes the thread messy and hard to read.

If you want to you can also add reference of this thread in your newly created thread.

We would be more than happy to help you on your new thread.

Thank you Movin,
I appreciate your polite response to forum users. Please note the following is given likewise.
I replied here because 1) I was speaking directly about the original posters question and 2) pointing out that the code you suggested was broken (ie the mission opening <?php tag) lastly, 3) I wanted clarity about why the code you suggested (even with the opening tag) broke my site and why the code that I found suggested elsewhere was so different. I don’t agree that my reply makes the thread hard to read when the reply is speaking directly about the original question.
It is my understanding that a thread is a singular issue or topic but that many voices can contribute or clarify. If this is more of a one-on-support ticket situation than I am mistaken.
My very reply here is because I have found at least 4 threads about this identical issue (with you responding to more than one of them) in a variety of colorlib theme areas and none have been marked as satisfactorily resolved.
What makes these forums hard to find helpful is when there are so many people starting threads about an identical problem. This is the only thread specific to Dazzling theme and I didn’t want to muddy the waters with an additional seperate threads about the same.
I am just bumbling my way around here because I know nothing about theme modification and trying to find others who have done it who might be able to help. You are actually trying to help me today with a seperate issue (that I could not find in another thread - so I started one.)
I am very respectfully in disagreement about how to use threads effectively, hence the private reply. I would be very interested to see if your advice here in this thread actually worked for Limoden.
Lisa

Thank you for replying in private.

I do answer multiple questions in a single if they are not complex in nature and related to the initial question which so not need much replies orelse i request to separate topics for each questions this is because if other users ask the same question like you then to save time and provide quick support we share the URL of existing topic like this so we have to not to make thread messy and hard to read.

This is just one part of thread complexity and the another point is this that every time you post the reply here everyone involved in the topic gets notified which is annoying for them and you can see the example of it in this topic https://colorlibsupport.com/t/sparkling-child-theme/page/5/

Yes you can assume this as one-on-support forum until you ask question directly to the topic creator or the topic creator replies in the topic to help you.

I am sure you understand this.

Hi,

I too tried to use the code but it showed error in sparkling child theme.

I want to add 728 x 90 ad in the header moving the header logo from center to side.

I have attached screenshot what actually I am trying.

Kindly suggest.

Regards,

Siddharth

@Siddharth This is old topic and this is Dazzling theme forum so to help us keep support thread separates could you please create your own thread for your question here https://colorlibsupport.com/c/sparkling/ instead of replying on others thread as it makes the thread messy and hard to read.

If you want to you can also add reference of this thread in your newly created thread.

We would be more than happy to help you on your new thread.