get_section( $section_id ) ) { $wp_customize->add_section( $section_id, array( 'title' => __( 'Containers', 'bongoto-woocommerce' ), 'priority' => 10, 'panel' => 'bongoto_general_panel', 'description' => __( 'Control the max-width of containers across the theme.', 'bongoto-woocommerce' ), ) ); } $items = array( 'bongoto_container_header' => __( 'Header Container (px)', 'bongoto-woocommerce' ), 'bongoto_container_footer' => __( 'Footer Container (px)', 'bongoto-woocommerce' ), 'bongoto_container_page' => __( 'Page Container (px)', 'bongoto-woocommerce' ), 'bongoto_container_post' => __( 'Post Container (px)', 'bongoto-woocommerce' ), ); foreach ( $items as $id => $label ) { $wp_customize->add_setting( $id, array( 'default' => 1200, 'transport' => 'refresh', 'sanitize_callback' => function ( $v ) { $v = is_numeric( $v ) ? (int) $v : 1200; if ( $v < 720 ) { $v = 720; } if ( $v > 1920 ) { $v = 1920; } return $v; }, ) ); $wp_customize->add_control( $id, array( 'label' => $label, 'section' => $section_id, 'type' => 'number', 'input_attrs' => array( 'min' => 720, 'max' => 1920, 'step' => 10, ), ) ); } }, 30 ); /** * Output container CSS variables. */ // NOTE: Use wp_add_inline_style instead of wp_head so this always overrides main.css on frontend. add_action( 'wp_enqueue_scripts', function () { // Ensure our main stylesheet is enqueued before attaching inline CSS. if ( ! wp_style_is( 'bongoto-woocommerce-main', 'enqueued' ) ) { return; } $header = (int) get_theme_mod( 'bongoto_container_header', 1200 ); $footer = (int) get_theme_mod( 'bongoto_container_footer', 1200 ); $page = (int) get_theme_mod( 'bongoto_container_page', 1200 ); $post = (int) get_theme_mod( 'bongoto_container_post', 1200 ); $header = max( 720, min( 1920, $header ) ); $footer = max( 720, min( 1920, $footer ) ); $page = max( 720, min( 1920, $page ) ); $post = max( 720, min( 1920, $post ) ); $css = ':root{' . '--bongoto-container-header:' . $header . 'px;' . '--bongoto-container-footer:' . $footer . 'px;' . '--bongoto-container-page:' . $page . 'px;' . '--bongoto-container-post:' . $post . 'px;' . '}'; // Use !important to override the base .container rules and any framework defaults. $css .= '.bt-header-inner.container, .site-header .container{max-width:var(--bongoto-container-header)!important;}'; $css .= '.site-footer .container{max-width:var(--bongoto-container-footer)!important;}'; $css .= 'body.single-post .site-main .container{max-width:var(--bongoto-container-post)!important;}'; $css .= 'body:not(.single-post) .site-main .container{max-width:var(--bongoto-container-page)!important;}'; // Elementor boxed container alignment. $css .= 'body:not(.single-post) .elementor-section.elementor-section-boxed>.elementor-container{max-width:var(--bongoto-container-page)!important;}'; $css .= 'body.single-post .elementor-section.elementor-section-boxed>.elementor-container{max-width:var(--bongoto-container-post)!important;}'; wp_add_inline_style( 'bongoto-woocommerce-main', $css ); } , 99 );