On this page
page_template_dropdown( string $default_template = '', string $post_type = 'page' )
Prints out option HTML elements for the page templates drop-down.
Parameters
$default_templatestring Optional-
The template file name.
Default:
'' $post_typestring Optional-
Post type to get templates for. Default
'post'.Default:
'page'
Source
File: wp-admin/includes/template.php. View all references
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>';
}
}
Related
Uses
| Uses | Description |
|---|---|
| get_page_templates() wp-admin/includes/theme.php | Gets the page templates available in this theme. |
| selected() wp-includes/general-template.php | Outputs the HTML selected attribute. |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
| esc_html() wp-includes/formatting.php | Escaping for HTML blocks. |
Used By
| Used By | Description |
|---|---|
| page_attributes_meta_box() wp-admin/includes/meta-boxes.php | Displays page attributes form fields. |
| WP_Posts_List_Table::inline_edit() wp-admin/includes/class-wp-posts-list-table.php | Outputs the hidden row displayed when inline editing |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/page_template_dropdown