page_template_dropdown( string $default_template = , string $post_type = ‘page’ )

In this article

Prints out option HTML elements for the page templates drop-down.

Parameters

$default_templatestringoptional
The template file name.

Default:''

$post_typestringoptional
Post type to get templates for. Default 'page'.

Default:'page'

Source

function page_template_dropdown( $default_template = '', $post_type = 'page' ) {
	$templates = get_page_templates( null, $post_type );

	ksort( $templates );

	foreach ( array_keys( $templates ) as $template ) {
		$selected = selected( $default_template, $templates[ $template ], false );
		echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>';
	}
}

Changelog

VersionDescription
4.7.0Added the $post_type parameter.
1.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.