The default_page_template_title WordPress PHP filter allows you to modify the title of the default page template displayed in the drop-down.
Usage
add_filter( 'default_page_template_title', 'your_custom_function', 10, 2 ); function your_custom_function( $label, $context ) { // your custom code here return $label; }
Parameters
$label
: (string) The display value for the default page template title.$context
: (string) Where the option label is displayed. Possible values include ‘meta-box’ or ‘quick-edit’.
More information
See WordPress Developer Resources: default_page_template_title
Examples
Change the default page template title
This example changes the default page template title to “Main Template”:
add_filter( 'default_page_template_title', 'change_default_template_title', 10, 2 ); function change_default_template_title( $label, $context ) { $label = 'Main Template'; return $label; }
Add a prefix to the default page template title
This example adds a prefix “My Site – ” to the default page template title:
add_filter( 'default_page_template_title', 'add_prefix_to_template_title', 10, 2 ); function add_prefix_to_template_title( $label, $context ) { $label = 'My Site - ' . $label; return $label; }
Change the default page template title in the meta-box only
This example changes the default page template title to “Custom Template” only in the meta-box context:
add_filter( 'default_page_template_title', 'change_template_title_metabox', 10, 2 ); function change_template_title_metabox( $label, $context ) { if ( 'meta-box' === $context ) { $label = 'Custom Template'; } return $label; }
Change the default page template title based on user role
This example changes the default page template title to “Editor Template” for users with the editor role:
add_filter( 'default_page_template_title', 'change_template_title_for_editors', 10, 2 ); function change_template_title_for_editors( $label, $context ) { if ( current_user_can( 'editor' ) ) { $label = 'Editor Template'; } return $label; }
Add the current date to the default page template title
This example appends the current date to the default page template title:
add_filter( 'default_page_template_title', 'add_date_to_template_title', 10, 2 ); function add_date_to_template_title( $label, $context ) { $current_date = date( 'Y-m-d' ); $label = $label . ' - ' . $current_date; return $label; }