get_uploaded_header_images

The timeline below displays how wordpress function get_uploaded_header_images has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Gets the header images uploaded for the active theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo Caching.
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = sanitize_url(wp_get_attachment_url($header->ID));
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = $header->ID;
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        $header_images[$header_index]['alt_text'] = get_post_meta($header->ID, '_wp_attachment_image_alt', true);
        if (isset($header_data['attachment_parent'])) {
            $header_images[$header_index]['attachment_parent'] = $header_data['attachment_parent'];
        } else {
            $header_images[$header_index]['attachment_parent'] = '';
        }
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}

WordPress Version: 5.9

/**
 * Gets the header images uploaded for the current theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo Caching.
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = esc_url_raw(wp_get_attachment_url($header->ID));
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = $header->ID;
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        $header_images[$header_index]['alt_text'] = get_post_meta($header->ID, '_wp_attachment_image_alt', true);
        if (isset($header_data['attachment_parent'])) {
            $header_images[$header_index]['attachment_parent'] = $header_data['attachment_parent'];
        } else {
            $header_images[$header_index]['attachment_parent'] = '';
        }
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}

WordPress Version: 5.5

/**
 * Gets the header images uploaded for the current theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo Caching.
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = esc_url_raw(wp_get_attachment_url($header->ID));
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = $header->ID;
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        $header_images[$header_index]['alt_text'] = get_post_meta($header->ID, '_wp_attachment_image_alt', true);
        $header_images[$header_index]['attachment_parent'] = isset($header_data['attachment_parent']) ? $header_data['attachment_parent'] : '';
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}

WordPress Version: 5.4

/**
 * Get the header images uploaded for the current theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo Caching.
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = esc_url_raw(wp_get_attachment_url($header->ID));
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = $header->ID;
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        $header_images[$header_index]['alt_text'] = get_post_meta($header->ID, '_wp_attachment_image_alt', true);
        $header_images[$header_index]['attachment_parent'] = isset($header_data['attachment_parent']) ? $header_data['attachment_parent'] : '';
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}

WordPress Version: 4.9

/**
 * Get the header images uploaded for the current theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo caching
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = esc_url_raw(wp_get_attachment_url($header->ID));
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = $header->ID;
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        $header_images[$header_index]['alt_text'] = get_post_meta($header->ID, '_wp_attachment_image_alt', true);
        $header_images[$header_index]['attachment_parent'] = isset($header_data['attachment_parent']) ? $header_data['attachment_parent'] : '';
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}

WordPress Version: 4.5

/**
 * Get the header images uploaded for the current theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo caching
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = esc_url_raw(wp_get_attachment_url($header->ID));
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = $header->ID;
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        $header_images[$header_index]['alt_text'] = get_post_meta($header->ID, '_wp_attachment_image_alt', true);
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}

WordPress Version: 4.3

/**
 * Get the header images uploaded for the current theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo caching
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = esc_url_raw(wp_get_attachment_url($header->ID));
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = basename($url);
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        $header_images[$header_index]['alt_text'] = get_post_meta($header->ID, '_wp_attachment_image_alt', true);
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}

WordPress Version: 3.9

/**
 * Get the header images uploaded for the current theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo caching
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = esc_url_raw(wp_get_attachment_url($header->ID));
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = basename($url);
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}

WordPress Version: 3.7

/**
 * Get the header images uploaded for the current theme.
 *
 * @since 3.2.0
 *
 * @return array
 */
function get_uploaded_header_images()
{
    $header_images = array();
    // @todo caching
    $headers = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true));
    if (empty($headers)) {
        return array();
    }
    foreach ((array) $headers as $header) {
        $url = esc_url_raw($header->guid);
        $header_data = wp_get_attachment_metadata($header->ID);
        $header_index = basename($url);
        $header_images[$header_index] = array();
        $header_images[$header_index]['attachment_id'] = $header->ID;
        $header_images[$header_index]['url'] = $url;
        $header_images[$header_index]['thumbnail_url'] = $url;
        if (isset($header_data['width'])) {
            $header_images[$header_index]['width'] = $header_data['width'];
        }
        if (isset($header_data['height'])) {
            $header_images[$header_index]['height'] = $header_data['height'];
        }
    }
    return $header_images;
}