Here's my goal:
I want to control the header image through the backend in the widget section (I added an image under my sidebar) through a widget that I create with WordPress.
Here's my code:
<?php
add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'theme-slug' ),
'id' => 'sidebar-1',
'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
'before_widget' => '<div>',
'after_widget' => '</div>',
) );
}
?>
and in the template I will call the sidbar in this way:
<?php dynamic_sidebar( 'sidebar-1' ); ?>
So far so good but what if I want to do something different, like:
<header style="background-image: url(<?php dynamic_sidebar( 'sidebar-1' ); ?>)"></header>
The problem of this approach is that the dynamic_sidebar function will call the entire <div>
with some extra markup, but my idea is to call only the image from the dynamic sidebar.
Is there any way to do that?