Written by me@grafxflow
18 Mar, 2013
16
7,918
You may want to add a widget to your WordPress theme header (or any page template) but have noticed that it doesn't appear in admin (Appearance->Widgets). Luckily it's possible with the following PHP code which makes it appear in admin and on your website page. The code is also based on a custom/from scratch theme.
1. First add this to your functions.php file.
(wp-content/themes/YOURTHEME/functions.php)
// The function to group all the widget areas //
function create_widgets_init() {
// The custom widget //
register_sidebars( 1,
array(
'name' => 'Head column',
'id' => 'head-column',
'description' => __('The header widget area, used for placing your custom widgets.'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>')
);
}
// ACTIVATE THE WIDGET(S) //
add_action( 'widgets_init', 'create_widgets_init' );
2. Then in your header.php file add. (wp-content/themes/YOURTHEME/header.php)
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('head-column') ) : ?>
<?php endif; ?>
24 Nov, 2013
07 Nov, 2012
26 Apr, 2018
I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!
Follow18 Dec, 2025
20 May, 2025
11 Jul, 2023
Views: 198,094
Views: 197,543
Views: 174,619
Views: 146,009
16 Response