wp_get_chromium_major_version()WP 7.1.0

Returns the major Chrome/Chromium version from the current request's User-Agent.

Matches all Chromium-based browsers (Chrome, Edge, Opera, Brave).

No Hooks.

Returns

int|null. The major Chrome version, or null if not a Chromium browser.

Usage

wp_get_chromium_major_version(): ?int;

Changelog

Since 7.1.0 Introduced.

wp_get_chromium_major_version() code WP 7.1

function wp_get_chromium_major_version(): ?int {
	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
		return null;
	}
	if ( preg_match( '#Chrome/(\d+)#', $_SERVER['HTTP_USER_AGENT'], $matches ) ) {
		return (int) $matches[1];
	}
	return null;
}