get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; // Add selective refresh support. if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.site-title a', 'render_callback' => 'barande_customize_partial_blogname', )); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => 'barande_customize_partial_blogdescription', )); } // Footer Settings Section $wp_customize->add_section( 'barande_footer_section', array( 'title' => __( 'Footer Settings', 'barande' ), 'priority' => 130, )); // Footer copyright text setting. $wp_customize->add_setting( 'barande_footer_copyright', array( 'default' => '', 'sanitize_callback' => 'sanitize_text_field', )); // Footer copyright text control. $wp_customize->add_control( 'barande_footer_copyright', array( 'label' => __( 'Copyright Text', 'barande' ), 'section' => 'barande_footer_section', 'type' => 'text', )); // Blog Layout Section $wp_customize->add_section( 'barande_layout_sec', array( 'title' => __( 'Blog Layout', 'barande' ), 'description' => __( 'Choose your preferred blog layout.', 'barande' ), )); // Blog layout setting. $wp_customize->add_setting( 'barande_layout_set', array( 'default' => 'grid', 'type' => 'theme_mod', 'sanitize_callback' => 'sanitize_key', )); // Blog layout control. $wp_customize->add_control( 'barande_ctrl_layout', array( 'label' => __( 'Select Layout', 'barande' ), 'section' => 'barande_layout_sec', 'settings' => 'barande_layout_set', 'type' => 'radio', 'choices' => array( 'classic' => __( 'Classic', 'barande' ), 'grid' => __( 'Grid', 'barande' ), ), )); // Add a section for category settings if not already added $wp_customize->add_section('post_category_settings', array( 'title' => __('Post Category Settings', 'barande'), 'priority' => 30, )); // Add a checkbox setting to enable/disable featured posts $wp_customize->add_setting('barande_enable_featured_post', array( 'default' => true, // Default to enabled 'sanitize_callback' => 'rest_sanitize_boolean', // Sanitize as boolean )); // Add a checkbox control for enabling/disabling featured posts $wp_customize->add_control('barande_enable_featured_post', array( 'label' => __('Enable Featured Post Section', 'barande'), 'section' => 'post_category_settings', 'type' => 'checkbox', )); // Add the category dropdown setting if not already added $wp_customize->add_setting('barande_selected_post_category', array( 'default' => '', 'sanitize_callback' => 'absint', // Ensure the category ID is an integer )); $categories = get_categories(array('hide_empty' => false)); $choices = array(); foreach ($categories as $category) { $choices[$category->term_id] = $category->name; } // Add a control for selecting the post category $wp_customize->add_control('barande_selected_post_category', array( 'label' => __('Select a Post Category', 'barande'), 'section' => 'post_category_settings', 'type' => 'select', 'choices' => $choices, )); // Add a custom title setting $wp_customize->add_setting('barande_custom_category_title', array( 'default' => '', // Default to empty 'sanitize_callback' => 'sanitize_text_field', // Sanitize as plain text )); // Add a control for the custom category title $wp_customize->add_control('barande_custom_category_title', array( 'label' => __('Custom Category Title', 'barande'), 'section' => 'post_category_settings', 'type' => 'text', 'description' => __('Enter a custom title for the category. If empty, the selected category name will be used.', 'barande'), )); } add_action( 'customize_register', 'barande_customize_register' ); /** * Render the site title for the selective refresh partial. */ function barande_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site tagline for the selective refresh partial. */ function barande_customize_partial_blogdescription() { bloginfo( 'description' ); } /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function barande_customize_preview_js() { wp_enqueue_script( 'barande-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), _S_VERSION, true ); } add_action( 'customize_preview_init', 'barande_customize_preview_js' );