W3cubDocs

/WordPress

page_template_dropdown( string $default = '', string $post_type = 'page' )

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

Parameters

$default

(string) (Optional) The template file name.

Default value: ''

$post_type

(string) (Optional) Post type to get templates for. Default 'post'.

Default value: 'page'

Source

File: wp-admin/includes/template.php

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

	ksort( $templates );

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

Changelog

Version Description
4.7.0 Added the $post_type parameter.
1.5.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/page_template_dropdown