wpseek.com
A WordPress-centric search engine for devs and theme authors



page_template_dropdown › WordPress Function

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

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



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>';
	}
}