Prints out option HTML elements for the page templates drop-down.
Parameters
$default_template
stringoptional- The template file name.
Default:
''
$post_type
stringoptional- 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>';
}
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.