Last active
June 4, 2019 19:22
-
-
Save timothyjensen/29980bb1598215199cccbf51e2b3dd5f to your computer and use it in GitHub Desktop.
Change the placeholder text for the post title field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add 'title_placeholder' to the array of arguments when registering the custom post type. | |
$cpt_args = array( | |
'title_placeholder' => 'Team member name', | |
); | |
register_post_type( 'team_members', $cpt_args ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'enter_title_here', 'prefix_change_title_placeholder_text' ); | |
/** | |
* Change the placeholder text for the post title field. | |
* | |
* @param string $title Default placeholder text. | |
* @return string | |
*/ | |
function prefix_title_placeholder_text( $title ) { | |
$post_type_object = get_post_type_object( get_post_type() ); | |
if ( empty( $post_type_object->title_placeholder ) ) { | |
return $title; | |
} | |
return $post_type_object->title_placeholder; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment