* * @link https://developer.wordpress.org/themes/functionality/custom-headers/ * * @package Starligh */ /** * Sample implementation of the Custom Header feature. * * @link https://developer.wordpress.org/themes/functionality/custom-headers/ * * @package Starligh */ function starlight_customiser_settings( $wp_customize ) { // Remove the default color settings in order to keep everything // in one place and easy to access _for the user_ $wp_customize->remove_section( 'colors' ); // header_image $wp_customize->add_setting( 'starlight_header_image_position' , array( 'default' => 'after-menu', 'transport' => 'refresh', 'sanitize_callback' => 'starlight_sanitize_choices' ) ); $wp_customize->add_control( 'starlight_header_image_position', array( 'label' => __( 'Header image position', 'starlight' ), 'description' => __( 'Show the header image before or after the menu.', 'starlight' ), 'section' => 'header_image', 'settings' => 'starlight_header_image_position', 'type' => 'radio', 'choices' => array( 'after-menu' => 'After header', 'before-menu' => 'Before header', ) ) ); $wp_customize->add_section( 'starlight_settings' , array( 'title' => __( 'Starlight theme settings', 'starlight' ), 'priority' => 30, ) ); $wp_customize->add_setting( 'starlight_primary_color' , array( 'default' => '#00A7FF', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_setting( 'starlight_background_color' , array( 'default' => '#F5F5F5', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'starlight_primary_color', array( 'label' => __( 'Primary color', 'starlight' ), 'section' => 'starlight_settings', 'settings' => 'starlight_primary_color', ) ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'starlight_background_color', array( 'label' => __( 'Background color', 'starlight' ), 'section' => 'starlight_settings', 'settings' => 'starlight_background_color', ) ) ); $wp_customize->add_setting( 'starlight_archive_layout' , array( 'type' => 'theme_mod', 'transport' => 'refresh', 'capability' => 'edit_theme_options', 'default' => 'default', 'sanitize_callback' => 'starlight_sanitize_choices' )); $wp_customize->add_control( 'starlight_archive_layout', array( 'label' => __( 'Archive layout', 'starlight' ), 'description' => __( 'How to list your articles. Compact will show small image with less information.', 'starlight' ), 'section' => 'starlight_settings', 'settings' => 'starlight_archive_layout', 'type' => 'radio', 'choices' => array( 'default' => 'Default', // This is the default one 'compact' => 'Compact' ), ) ); $wp_customize->add_setting( 'starlight_typography_type' , array( 'type' => 'theme_mod', 'transport' => 'refresh', 'capability' => 'edit_theme_options', 'default' => 'sans', 'sanitize_callback' => 'starlight_sanitize_choices' )); $wp_customize->add_control( 'starlight_typography_type', array( 'label' => __( 'Set typography type', 'starlight' ), 'description' => __( 'Book reading is font good for long reading sessions. It will change only the content of your articles, the rest will remain unchanged.', 'starlight' ), 'section' => 'starlight_settings', 'settings' => 'starlight_typography_type', 'type' => 'radio', 'choices' => array( 'sans-serif' => 'Book reading', 'sans' => 'System fonts', ) ) ); $wp_customize->add_setting( 'starlight_sidebar_position' , array( 'type' => 'theme_mod', 'transport' => 'refresh', 'capability' => 'edit_theme_options', 'default' => 'right', 'sanitize_callback' => 'starlight_sanitize_choices' )); $wp_customize->add_control( 'starlight_sidebar_position', array( 'label' => __( 'Sidebar position', 'starlight' ), 'description' => __( 'Chose between left, right and no sidebar.', 'starlight' ), 'section' => 'starlight_settings', 'settings' => 'starlight_sidebar_position', 'type' => 'radio', 'choices' => array( 'right' => 'Right sidebar', 'left' => 'Left sidebar', 'none' => 'No sidebar', ), ) ); $wp_customize->add_setting( 'starlight_spacings' , array( 'type' => 'theme_mod', 'transport' => 'refresh', 'capability' => 'edit_theme_options', 'default' => 'spacing-cozy', 'sanitize_callback' => 'starlight_sanitize_choices' )); $wp_customize->add_control( 'starlight_spacings', array( 'label' => __( 'White space', 'starlight' ), 'description' => __( 'How much white space you want on your site? Different settings will allow more or less content to be visible on one scroll.', 'starlight' ), 'section' => 'starlight_settings', 'settings' => 'starlight_spacings', 'type' => 'radio', 'choices' => array( 'spacing-cozy' => 'Cozy', // This is the default one 'spacing-moderate' => 'Moderate' ), ) ); } add_action( 'customize_register', 'starlight_customiser_settings' ); function starlight_sanitize_choices( $input, $setting ) { global $wp_customize; $control = $wp_customize->get_control( $setting->id ); if ( array_key_exists( $input, $control->choices ) ) { return esc_attr( $input ); } else { return esc_attr( $setting->default ); } } /** * Set up the WordPress core custom header feature. * * @uses starlight_header_style() */ function starlight_custom_header_setup() { add_theme_support( 'custom-header', apply_filters( 'starlight_custom_header_args', array( 'default-image' => '', 'default-text-color' => '000000', 'width' => 1920, 'height' => 500, 'flex-height' => true, 'wp-head-callback' => 'starlight_header_style', ) ) ); } add_action( 'after_setup_theme', 'starlight_custom_header_setup' ); if ( ! function_exists( 'starlight_header_style' ) ) : /** * Styles the header image and text displayed on the blog. * * @see starlight_custom_header_setup(). * @see https://codex.wordpress.org/Theme_Customization_API */ function starlight_header_style() { $header_text_color = get_header_textcolor(); $starlight_primary_color = esc_attr ( get_theme_mod( 'starlight_primary_color', '#00A7FF' ) ); $starlight_background_color = esc_attr ( get_theme_mod( 'starlight_background_color', '#f0f0f0' ) ); // If we get this far, we have custom styles. Let's do this. ?>