add_panel( 'typography_panel', array( 'title' => __( 'Typography', 'hotelflix' ), 'priority' => 50, ) ); $wp_customize->add_section( 'body_and_content', array( 'title' => __( 'Body & content', 'hotelflix' ), 'panel' => 'typography_panel', 'priority' => 10, ) ); /* Font family */ $wp_customize->add_setting( 'body_font_family', array( 'default' => 'Poppins', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'body_font_family', array( 'type' => 'select', 'section' => 'body_and_content', 'label' => __( 'Select a font family', 'hotelflix' ), 'choices' => hotelflix_fonts_list(), ) ); /* Font size */ $wp_customize->add_setting( 'body_font_size', array( 'default' => '16', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'body_font_size', array( 'type' => 'number', 'section' => 'body_and_content', 'label' => __( 'Select a base font-size (px) for the body', 'hotelflix' ), 'input_attrs' => array( 'min' => 14, 'max' => 24, 'step' => 1, ), ) ); /* Font weight */ $wp_customize->add_setting( 'body_font_weight', array( 'default' => '400', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'body_font_weight', array( 'type' => 'select', 'section' => 'body_and_content', 'label' => __( 'Select a font weight', 'hotelflix' ), 'choices' => array( '400' => __( '400 Normal', 'hotelflix' ), '700' => __( '700 Bold', 'hotelflix' ), ), ) ); /* line height */ $wp_customize->add_setting( 'body_line_height', array( 'default' => '1.5', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'body_line_height', array( 'type' => 'select', 'section' => 'body_and_content', 'label' => __( 'Select a default line-height for the body', 'hotelflix' ), 'choices' => array( '1' => __( '1', 'hotelflix' ), '1.5' => __( '1.5', 'hotelflix' ), '2' => __( '2', 'hotelflix' ), '2.5' => __( '2.5', 'hotelflix' ), '3' => __( '3', 'hotelflix' ), '3.5' => __( '3.5', 'hotelflix' ), ), ) ); /** * Headings */ for ( $i = 1; $i < 7; $i++ ) { $wp_customize->add_section( 'heading_' . $i, array( 'title' => 'H' . $i . ' ' . __( 'Heading', 'hotelflix' ), 'priority' => 80, 'panel' => 'typography_panel', ) ); $wp_customize->add_setting( 'heading_ ' . $i . '_font_family', array( 'default' => 'Teko', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'heading_ ' . $i . '_font_family', array( 'type' => 'select', 'section' => 'heading_' . $i, 'label' => __( 'Select a font family', 'hotelflix' ), 'choices' => hotelflix_fonts_list(), ) ); /* Font size heading*/ $wp_customize->add_setting( 'heading_ ' . $i . '_font_size', array( 'default' => '', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'heading_ ' . $i . '_font_size', array( 'type' => 'number', 'section' => 'heading_' . $i, 'label' => 'H' . $i . ' ' . __( 'Font size', 'hotelflix' ), 'description' => __( 'Select a font size for the heading (px).', 'hotelflix' ), 'input_attrs' => array( 'min' => 20, 'max' => 94, 'step' => 1, ), ) ); /* Font weight headings */ $wp_customize->add_setting( 'heading_' . $i . '_font_weight', array( 'default' => '700', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'heading_' . $i . '_font_weight', array( 'type' => 'select', 'section' => 'heading_' . $i, 'label' => 'H' . $i . ' ' . __( 'Select a font weight', 'hotelflix' ), 'choices' => array( '400' => __( '400 Normal', 'hotelflix' ), '700' => __( '700 Bold', 'hotelflix' ), ), ) ); /* text-transform for headings */ $wp_customize->add_setting( 'heading_' . $i . '_text_transform', array( 'default' => 'initial', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'heading_' . $i . '_text_transform', array( 'type' => 'select', 'section' => 'heading_' . $i, 'label' => 'H' . $i . ' ' . __( 'Capitalization', 'hotelflix' ), 'description' => __( 'You can choose to show the text as all uppercase or capitilized.', 'hotelflix' ), 'choices' => array( 'initial' => __( 'Default', 'hotelflix' ), 'uppercase' => __( 'Uppercase', 'hotelflix' ), 'capitalize' => __( 'Capitalized', 'hotelflix' ), ), ) ); /* Line height for headings */ $wp_customize->add_setting( 'heading_' . $i . '_line_height', array( 'default' => '2', 'sanitize_callback' => 'hotelflix_sanitize_select', ) ); $wp_customize->add_control( 'heading_' . $i . '_line_height', array( 'type' => 'select', 'section' => 'heading_' . $i, 'label' => 'H' . $i . ' ' . __( 'Line height', 'hotelflix' ), 'choices' => array( '1' => __( '1', 'hotelflix' ), '1.5' => __( '1.5', 'hotelflix' ), '2' => __( '2', 'hotelflix' ), '2.5' => __( '2.5', 'hotelflix' ), ), ) ); } } add_action( 'customize_register', 'hotelflix_customize_register_typography' ); /** * Add custom typography styles. */ function hotelflix_typography_css() { echo ''; } add_action( 'wp_head', 'hotelflix_typography_css' ); /** * Enqueue the selected fonts. */ function hotelflix_custom_fonts() { $body_font = get_theme_mod( 'body_font_family', 'Poppins' ); if ( ! empty( $body_font ) && $body_font !== 'Poppins' ) { $body_font = '//fonts.googleapis.com/css2?family=' . $body_font . ':wght@200;300;400;500;600;700&& display=swap'; wp_enqueue_style( 'hotelflix_body_font', $body_font, array(), null ); } $heading_fonts = array(); for ( $i = 1; $i < 7; $i++ ) { if ( get_theme_mod( 'heading_ ' . $i . '_font_family', 'Teko' ) !== 'Teko' ) { $heading_fonts[] = get_theme_mod( 'heading_ ' . $i . '_font_family' ); } } $heading_fonts = array_unique( $heading_fonts ); $heading_fonts_final = ''; foreach ( $heading_fonts as $fonts ) { $heading_fonts_final .= 'family=' . $fonts . ':wght@200;300;400;500;600;700&&' ; } if ( ! empty( $heading_fonts_final ) ) { wp_enqueue_style( 'hotelflix_heading_fonts', '//fonts.googleapis.com/css2?' . $heading_fonts_final . 'display=swap', array(), null ); } } add_action( 'wp_enqueue_scripts', 'hotelflix_custom_fonts' );