wp_get_default_extension_for_mime_type() WordPress Function

The wp_get_default_extension_for_mime_type() function allows you to get the default file extension for a given mime type. This is useful if you need to determine the file extension for a file that doesn't have one, or if you want to change the extension of a file.

wp_get_default_extension_for_mime_type( string $mime_type ) #

Returns first matched extension for the mime-type, as mapped from wp_get_mime_types().


Parameters

$mime_type

(string)(Required)


Top ↑

Return

(string|false)


Top ↑

Source

File: wp-includes/functions.php

function wp_get_default_extension_for_mime_type( $mime_type ) {
	$extensions = explode( '|', array_search( $mime_type, wp_get_mime_types(), true ) );

	if ( empty( $extensions[0] ) ) {
		return false;
	}

	return $extensions[0];
}


Top ↑

Changelog

Changelog
VersionDescription
5.8.1Introduced.

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