A WordPress-centric search engine for devs and theme authors



page_template_dropdown ›

Since1.5.0
Deprecatedn/a
page_template_dropdown ( $default = '', $post_type = 'page' )
Parameters: (2)
  • (string) $default Optional. The template file name. Default empty.
    Required: No
    Default: (empty)
  • (string) $post_type Optional. Post type to get templates for. Default 'post'.
    Required: No
    Default: 'page'
Defined at:
Codex:
Change Log:
  • 4.7.0 Added the ` $post_type` parameter.

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



Source

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='" . $templates[ $template ] . "' $selected>$template</option>";
	}
}