'; $output .= sprintf( '%s', esc_url(get_category_link($category->term_id)), esc_html($category->name) ); $output .= ''; return $output; } /** * Display Category Badge * * Echoes the category badge HTML. * * @param int $post_id Optional. Post ID. Defaults to current post. * @param bool $force_show Optional. Force display regardless of settings. Default false. */ function apus_the_category_badge($post_id = null, $force_show = false) { echo apus_get_category_badge($post_id, $force_show); } /** * Check if Category Badge is Enabled * * @return bool True if enabled, false otherwise. */ function apus_is_category_badge_enabled() { return (bool) get_theme_mod('apus_category_badge_enabled', true); } /** * Register Category Badge Settings in Customizer * * Adds controls to enable/disable category badges. * * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function apus_category_badge_customizer($wp_customize) { // Add section $wp_customize->add_section('apus_category_badge', array( 'title' => __('Category Badge', 'apus-theme'), 'priority' => 31, )); // Enable/Disable setting $wp_customize->add_setting('apus_category_badge_enabled', array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean', 'transport' => 'refresh', )); $wp_customize->add_control('apus_category_badge_enabled', array( 'label' => __('Enable Category Badge', 'apus-theme'), 'description' => __('Show the first category as a badge above the post title in single posts.', 'apus-theme'), 'section' => 'apus_category_badge', 'type' => 'checkbox', )); // Badge background color $wp_customize->add_setting('apus_category_badge_bg_color', array( 'default' => '#0073aa', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', )); $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'apus_category_badge_bg_color', array( 'label' => __('Badge Background Color', 'apus-theme'), 'section' => 'apus_category_badge', ))); // Badge text color $wp_customize->add_setting('apus_category_badge_text_color', array( 'default' => '#ffffff', 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', )); $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'apus_category_badge_text_color', array( 'label' => __('Badge Text Color', 'apus-theme'), 'section' => 'apus_category_badge', ))); } add_action('customize_register', 'apus_category_badge_customizer'); /** * Output Category Badge Inline Styles * * Outputs custom CSS for category badge colors. */ function apus_category_badge_styles() { $bg_color = get_theme_mod('apus_category_badge_bg_color', '#0073aa'); $text_color = get_theme_mod('apus_category_badge_text_color', '#ffffff'); $css = " "; echo $css; } add_action('wp_head', 'apus_category_badge_styles'); /** * Customize Preview JS for Live Preview * * Adds live preview support for category badge color changes. */ function apus_category_badge_customize_preview_js() { ?>