This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Reply To: Adding a Widget to Header Right

#975
Jason Bobich
Keymaster

Awesome, I’m glad to see you’re reading the tutorials and trying to take an initiative to figure out this stuff.

If you’re wanting to make PHP customizations, you are going to have to learn the basics of PHP — how to create a function, what variables are, what arrays are, etc — and how a WordPress functions.php file works. There’s just no way around this. All of your PHP customizations — your new widget area, your action hook modifications, everything — are going to be placed within the functions.php of your Child theme below where the themeblvd.php framework file is included.

So, in general, it’s a good idea to start familiarizing yourself with the hook system itself and what a WordPress action hook even is. So, your first question is basically “How do I put something in the right side of the header?”

And the answer would be to hook your custom content to “themeblvd_header_addon” and then position it with CSS. You can quickly see that by checking out the actions map:

http://dev.themeblvd.com/tutorial/primary-framework-action-hooks/

With Swagger specifically, you’re going to have to unhook what’s already there. So an example of just outputting some text would be to do something like this:

/**
 * My header content
 */
function my_header_content() {
	echo 'This content will show in the header.';
}
remove_all_actions( 'themeblvd_header_addon' );
add_action( 'themeblvd_header_addon', 'my_header_content' );

The next question is essentially, “How do I create and display a widget area?” If you’re just trying to do this in WordPress in general, it’s very easy. Register it from your Child theme’s functions.php and display it within whatever function you’re hooking into the header.

Now if you want to get fancy and use some of the framework’s unique things, you can register a “sidebar location.” This is what you were reading about in that tutorial. Basically this means that now if you wanted you could use the tools at Appearance > Widget Areas to then create custom widget areas that could then be swapped into that header location depending on different pages and what not.

The full breakdown on that is here:

http://dev.themeblvd.com/tutorial/widget-areas-for-the-end-user/#widget-area-locations

http://dev.themeblvd.com/tutorial/default-widget-area-locations/

http://dev.themeblvd.com/tutorial/addremove-widget-area-location/

Expanding on the example I gave above to go with the code you were originally asking about, it would go something like this:

/**
 * Add new sidebar location.
 */
themeblvd_add_sidebar_location( 'my_header_widget_area', 'My Header Widget Area', 'collapsible' );

/**
 * My header content
 */
function my_header_content() {
	themeblvd_display_sidebar( 'my_header_widget_area' );
}
remove_all_actions( 'themeblvd_header_addon' );
add_action( 'themeblvd_header_addon', 'my_header_content' );