prepend and display custom header widget area
Question
so in my functions.php i have a hook as per theme documentation in prepending content before the body. i also create a widget area, which i’d like to be the prepend content, as follows:
// create custom header widget area
function wpb_widgets_init() {
register_sidebar( array(
'name' => 'Custom Header Widget Area',
'id' => 'custom-header-widget',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="chw-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'wpb_widgets_init' );
// prepend and display custom header widget area
add_action( 'before', 'uncode_child_hook_before' );
function uncode_child_hook_before(){
echo <?php
if ( is_active_sidebar( 'custom-header-widget' ) ) : ?>
<div id="header-widget-area" class="chw-widget-area widget-area" role="complementary">
<?php dynamic_sidebar( 'custom-header-widget' ); ?>
</div>
<?php endif; ?>;
}
something must be off with my syntax- i’m a total php novice. thanks in advance.
0
child-theme, functions, hooks, widgets
4 years
2020-03-26T20:51:03-05:00
2020-03-26T20:51:03-05:00 0 Answers
137 views
0
Leave an answer