is_random_header_image() WordPress Function

This function allows you to check if a random header image is being used.

is_random_header_image( string $type = 'any' ) #

Checks if random header image is in use.


Description

Always true if user expressly chooses the option in Appearance > Header. Also true if theme has multiple header images registered, no specific header image is chosen, and theme turns on random headers with add_theme_support().


Top ↑

Parameters

$type

(string)(Optional)The random pool to use. Possible values include 'any', 'default', 'uploaded'.

Default value: 'any'


Top ↑

Return

(bool)


Top ↑

Source

File: wp-includes/theme.php

1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
function is_random_header_image( $type = 'any' ) {
    $header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );
 
    if ( 'any' === $type ) {
        if ( 'random-default-image' === $header_image_mod
            || 'random-uploaded-image' === $header_image_mod
            || ( '' !== get_random_header_image() && empty( $header_image_mod ) )
        ) {
            return true;
        }
    } else {
        if ( "random-$type-image" === $header_image_mod ) {
            return true;
        } elseif ( 'default' === $type && empty( $header_image_mod ) && '' !== get_random_header_image() ) {
            return true;
        }
    }
 
    return false;
}


Top ↑

Changelog

Changelog
VersionDescription
3.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More