我有一个为目录创建的自定义帖子类型,该目录最终将按字母顺序排序。我将按标题的字母顺序对帖子进行排序,所以我想确保标题输入为姓/名。有没有办法将自定义帖子中的默认帮助文本——“在此处输入标题”更改为其他内容?
更改自定义帖子类型的“在此处输入标题”帮助文本
5 个回复
最合适的回答,由SO网友:Rarst 整理而成
无法显式自定义该字符串。但它是通过转换函数传递的,因此很容易过滤。
尝试以下方式(不要忘记更改您的帖子类型):
add_filter(\'gettext\',\'custom_enter_title\');
function custom_enter_title( $input ) {
global $post_type;
if( is_admin() && \'Enter title here\' == $input && \'your_post_type\' == $post_type )
return \'Enter Last Name, Followed by First Name\';
return $input;
}
SO网友:Dave Romsey
我知道我来这里的聚会有点晚了,但我想补充一点enter_title_here
WordPress v3中专门为此目的添加了过滤器。1.
add_filter( \'enter_title_here\', \'custom_enter_title\' );
function custom_enter_title( $input ) {
if ( \'your_post_type\' === get_post_type() ) {
return __( \'Enter your name here\', \'your_textdomain\' );
}
return $input;
}
更改your_post_type
和your_textdomain
以匹配您自己的帖子类型名称和文本域。SO网友:Abhik
很抱歉把这个问题从坟墓里挖出来,但自从WordPress 3.1以来,提供了一个更好的解决方案。这个enter_title_here
滤器
function change_default_title( $title ){
$screen = get_current_screen();
// For CPT 1
if ( \'custom_post_type_1\' == $screen->post_type ) {
$title = \'CPT1 New Title\';
// For CPT 2
} elseif ( \'custom_post_type_2\' == $screen->post_type ) {
$title = \'CPT2 New Title\';
// For Yet Another CPT
} elseif ( \'custom_post_type_3\' == $screen->post_type ) {
$title = \'CPT3 New Title\';
}
// And, so on
return $title;
}
add_filter( \'enter_title_here\', \'change_default_title\' );
SO网友:Martin-Al
进去看看wp-admin/edit-form-advanced.php
第246行(第329行,自WP3.5起)
<label class="screen-reader-text" id="title-prompt-text" for="title">
<?php echo apply_filters( \'enter_title_here\', __( \'Enter title here\' ), $post ); ?>
</label>
SO网友:fuxia
获取所需标题格式的最佳方法是完全删除标题,并为具有适当标签的名称部分添加两个自定义字段。保存帖子后,根据PHP创建标题。
结束