Problem with adding 2 widgets to header area
-
Hi, I have the following problem:
I want to replace the header image/video area with 2 widget areas by using a child theme. These areas should be site by site, like standard footer1 and footer2.I managed to add 1 header widget area and removing the space caused by the header image/video area by playing around with the styling in the child theme’s live preview.
However, if I add the second header widget area, live preview stops working and I don’t want to activate the child theme until I know that everything works like it should.
This is my child theme’s functions.php code (with the not working area commented out):
<?php function my_theme_enqueue_styles() { $parent_style = 'twentyseventeen-style'; // This is 'twentyseventeen-style' for the Twenty Seventeen theme. wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), wp_get_theme()->get('Version') ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); // creating header widget area function wpb_widgets_init() { register_sidebar( array( 'name' => 'Header Widget 1', 'id' => 'header-widget', 'before_widget' => '<div class="hw-widget">', 'after_widget' => '</div>', 'before_title' => '<h2 class="hw-title">', 'after_title' => '</h2>', ) ); } add_action( 'widgets_init', 'wpb_widgets_init' ); /* function wpb_widgets_init() { register_sidebar( array( 'name' => 'Header Widget 2', 'id' => 'header-widget2', 'before_widget' => '<div class="hw-widget">', 'after_widget' => '</div>', 'before_title' => '<h2 class="hw-title">', 'after_title' => '</h2>', ) ); } add_action( 'widgets_init', 'wpb_widgets_init' ); */ ?>
This is the child theme’s header.php:
<?php /** * The header for our theme * * This is the template that displays all of the <head> section and everything up until <div id="content"> * * @link https://developer.www.ads-software.com/themes/basics/template-files/#template-partials * * @package WordPress * @subpackage Twenty_Seventeen * @since 1.0 * @version 1.0 */ ?><!DOCTYPE html> <html <?php language_attributes(); ?> class="no-js no-svg"> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="profile" href="https://gmpg.org/xfn/11"> <?php wp_head(); ?> </head> <body <?php body_class(); ?>> <div id="page" class="site"> <a class="skip-link screen-reader-text" href="#content"><?php _e( 'Skip to content', 'twentyseventeen' ); ?></a> <header id="masthead" class="site-header" role="banner"> <?php get_template_part( 'template-parts/header/header', 'image' ); ?> <?php if ( has_nav_menu( 'top' ) ) : ?> <div class="navigation-top"> <div class="wrap"> <?php get_template_part( 'template-parts/navigation/navigation', 'top' ); ?> </div><!-- .wrap --> </div><!-- .navigation-top --> <?php endif; ?> <?php //displaying custom header widget1 if ( is_active_sidebar( 'header-widget' ) ) : ?> <div id="header-widget-area" class="hw-widget widget-area" role="complementary"> <?php dynamic_sidebar( 'header-widget' ); ?> </div> <?php endif; ?> <?php //displaying custom header widget2 if ( is_active_sidebar( 'header-widget2' ) ) : ?> <div id="header-widget-area2" class="hw-widget widget-area" role="complementary"> <?php dynamic_sidebar( 'header-widget2' ); ?> </div> <?php endif; ?> </header><!-- #masthead --> <?php /* * If a regular post or page, and not the front page, show the featured image. * Using get_queried_object_id() here since the $post global may not be set before a call to the_post(). */ if ( ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) && has_post_thumbnail( get_queried_object_id() ) ) : echo '<div class="single-featured-image-header">'; echo get_the_post_thumbnail( get_queried_object_id(), 'twentyseventeen-featured-image' ); echo '</div><!-- .single-featured-image-header -->'; endif; ?> <div class="site-content-contain"> <div id="content" class="site-content">
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Problem with adding 2 widgets to header area’ is closed to new replies.