is_random_header_image example


function get_header_image() {
    $url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );

    if ( 'remove-header' === $url ) {
        return false;
    }

    if ( is_random_header_image() ) {
        $url = get_random_header_image();
    }

    /** * Filters the header image URL. * * @since 6.1.0 * * @param string $url Header image URL. */
    $url = apply_filters( 'get_header_image', $url );

    

    public function show_header_selector( $type = 'default' ) {
        if ( 'default' === $type ) {
            $headers = $this->default_headers;
        } else {
            $headers = get_uploaded_header_images();
            $type    = 'uploaded';
        }

        if ( 1 < count( $headers ) ) {
            echo '<div class="random-header">';
            echo '<label><input name="default-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />';
            _e( '<strong>Random:</strong> Show a different image on each page.' );
            echo '</label>';
            echo '</div>';
        }

        echo '<div class="available-headers">';

        foreach ( $headers as $header_key => $header ) {
            $header_thumbnail = $header['thumbnail_url'];
            $header_url       = $header['url'];
            $header_alt_text  = empty( $header['alt_text'] ) ? '' : $header['alt_text'];

            

function get_media_states( $post ) {
    static $header_images;

    $media_states = array();
    $stylesheet   = get_option( 'stylesheet' );

    if ( current_theme_supports( 'custom-header' ) ) {
        $meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true );

        if ( is_random_header_image() ) {
            if ( ! isset( $header_images ) ) {
                $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
            }

            if ( $meta_header === $stylesheet && in_array( $post->ID, $header_images, true ) ) {
                $media_states[] = __( 'Header Image' );
            }
        } else {
            $header_image = get_header_image();

            // Display "Header Image" if the image was ever used as a header image.
Home | Imprint | This part of the site doesn't use cookies.