[英]Change Wordpress Post Title Placeholder
我正在創建自定義帖子類型,並希望在“創建新帖子”部分的標題字段中操作占位符文本。
要求:
- 只能針對一種特定的帖子類型,而不是針對所有帖子。
- 它不能反映帖子類型的名稱,它必須是完全自定義的文本。
- 它不必可從 wordpress 管理部分進行編輯,自定義文本可以放置在 functions.php 文件中的函數內。
您可以將此片段放在您的functions.php中
function change_default_title( $title ){
$screen = get_current_screen();
if ( 'your_custom_post_type' == $screen->post_type ){
$title = 'Your custom placeholder text';
}
return $title;
}
add_filter( 'enter_title_here', 'change_default_title' );
那應該改變頭銜。
在以下網址找到: https : //gist.github.com/FStop/3094617
您也可以將其用於多種帖子類型
add_filter('enter_title_here', 'my_title_place_holder' , 20 , 2 );
function my_title_place_holder($title , $post){
// For Activities
if( $post->post_type == 'activities' ){
$my_title = "Activity Name";
return $my_title;
}
// For Instructors
elseif( $post->post_type == 'instructors' ){
$my_title = "Instructor Name";
return $my_title;
}
return $title;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.