page_template_dropdown() WordPress Function
The page_template_dropdown() function allows you to select a custom page template for a specific post or page. This can be useful if you want to use a different template for a specific post or page, or if you want to change the template for an existing post or page.
page_template_dropdown( string $default_template = '', string $post_type = 'page' ) #
Prints out option HTML elements for the page templates drop-down.
Parameters
- $default_template
(string)(Optional) The template file name.
Default value: ''
- $post_type
(string)(Optional) Post type to get templates for. Default 'post'.
Default value: 'page'
Source
File: wp-admin/includes/template.php
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>'; } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.7.0 | Added the $post_type parameter. |
1.5.0 | Introduced. |