get_the_title($post_id), 'loading' => 'lazy', 'class' => 'featured-image', ); // Merge with custom attributes $attributes = wp_parse_args($attr, $default_attr); // Get the thumbnail HTML $thumbnail = get_the_post_thumbnail($post_id, $size, $attributes); if (empty($thumbnail)) { return ''; } // Wrap in container div $output = '
'; $output .= $thumbnail; $output .= '
'; return $output; } /** * Display Featured Image * * Echoes the featured image HTML. * * @param int $post_id Optional. Post ID. Defaults to current post. * @param string $size Optional. Image size. Default 'apus-featured-large'. * @param array $attr Optional. Additional attributes for the image. * @param bool $force_show Optional. Force display regardless of settings. Default false. */ function apus_the_featured_image($post_id = null, $size = 'apus-featured-large', $attr = array(), $force_show = false) { echo apus_get_featured_image($post_id, $size, $attr, $force_show); } /** * Check if Featured Images are Enabled for Post Type * * @param string $post_type Optional. Post type. Defaults to current post type. * @return bool True if enabled, false otherwise. */ function apus_is_featured_image_enabled($post_type = '') { if (empty($post_type)) { $post_type = get_post_type(); } $option_key = 'apus_featured_image_' . $post_type; return (bool) get_theme_mod($option_key, true); } /** * Register Featured Image Settings in Customizer * * Adds controls to enable/disable featured images per post type. * * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function apus_featured_image_customizer($wp_customize) { // Add section $wp_customize->add_section('apus_featured_images', array( 'title' => __('Featured Images', 'apus-theme'), 'priority' => 30, )); // Get public post types $post_types = get_post_types(array('public' => true), 'objects'); foreach ($post_types as $post_type) { // Skip attachments if ($post_type->name === 'attachment') { continue; } $setting_id = 'apus_featured_image_' . $post_type->name; // Add setting $wp_customize->add_setting($setting_id, array( 'default' => true, 'sanitize_callback' => 'wp_validate_boolean', 'transport' => 'refresh', )); // Add control $wp_customize->add_control($setting_id, array( 'label' => sprintf( /* translators: %s: post type label */ __('Enable for %s', 'apus-theme'), $post_type->labels->name ), 'section' => 'apus_featured_images', 'type' => 'checkbox', )); } } add_action('customize_register', 'apus_featured_image_customizer');