WordPress at a glance

page_template_dropdown() WP 1.0

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

  • Since 4.7.0 Added the $post_type parameter.
Works based on: get_page_templates()

No Hooks.

Return

Nothing (null).

Usage

page_template_dropdown( $default, $post_type );
$default(string)
The template file name.
Default: ''
$post_type(string)
Post type to get templates for.
Default: 'post'

Code of page_template_dropdown: wp-admin/includes/template.php VER 4.9.8

<?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>";
	}
}

Related Functions

From tag: _dropdown (select options list)

More from category: Pages

No comments
    Hello, !     Log In . Register