Using WordPress ‘has_header_video()’ PHP function

The has_header_video() WordPress PHP function checks if a header video is set or not.

Usage

if (has_header_video()) {
    // Your custom code here
}

Parameters

This function does not have any parameters.

More information

See WordPress Developer Resources: has_header_video()

Examples

Display header video if set

In this example, we check if a header video is set and display it using the the_custom_header_markup() function.

if (has_header_video()) {
    the_custom_header_markup();
}

Display text if no header video

In this example, we display a message if there is no header video set.

if (!has_header_video()) {
    echo '<h2>No header video found.</h2>';
}

Add a CSS class if header video is set

In this example, we add a CSS class to the body tag if a header video is set.

<body <?php body_class(has_header_video() ? 'has-header-video' : ''); ?>>

Display a default video if no header video is set

In this example, we display a default video if no header video is set.

if (has_header_video()) {
    the_custom_header_markup();
} else {
    echo '<video src="/path/to/default-video.mp4" autoplay loop></video>';
}

Display a different header image based on header video status

In this example, we display a different header image depending on whether a header video is set or not.

if (has_header_video()) {
    echo '<img src="/path/to/header-image-video.jpg" alt="Header Image">';
} else {
    echo '<img src="/path/to/header-image-default.jpg" alt="Header Image">';
}