wp_ext2type() WordPress Function

The wp_ext2type() function allows you to get the file type from its extension. This is useful for determining the correct file type for a given extension.

wp_ext2type( string $ext ) #

Retrieve the file type based on the extension name.


Parameters

$ext

(string)(Required)The extension to search.


Top ↑

Return

(string|void) The file type, example: audio, video, document, spreadsheet, etc.


Top ↑

Source

File: wp-includes/functions.php

function wp_ext2type( $ext ) {
	$ext = strtolower( $ext );

	$ext2type = wp_get_ext_types();
	foreach ( $ext2type as $type => $exts ) {
		if ( in_array( $ext, $exts, true ) ) {
			return $type;
		}
	}
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.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
Show More