【发布时间】:2014-12-03 04:25:08
【问题描述】:
我正在创建自定义帖子类型,并希望在“创建新帖子”部分的标题字段中操作占位符文本。
要求:
- 它只能针对一种特定的帖子类型,而不是针对所有帖子。
- 不能反映帖子类型的名称,必须是完全自定义的文字。
- 它不必在 wordpress 管理部分进行编辑,自定义文本可以放在 functions.php 文件中的函数内。
【问题讨论】:
我正在创建自定义帖子类型,并希望在“创建新帖子”部分的标题字段中操作占位符文本。
要求:
- 它只能针对一种特定的帖子类型,而不是针对所有帖子。
- 不能反映帖子类型的名称,必须是完全自定义的文字。
- 它不必在 wordpress 管理部分进行编辑,自定义文本可以放在 functions.php 文件中的函数内。
【问题讨论】:
您也可以将其用于多种帖子类型
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;
}
【讨论】:
你可以把这个sn-p放在你的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' );
这应该改变标题。
【讨论】: