我试图在特定帖子类型的默认html编辑器上显示占位符。代码如下所示:
add_filter(\'the_editor\',\'add_placeholder_event\');
function add_placeholder_event( $html ){
if ( \'event\' == $post->post_type )
$html = preg_replace(\'/<textarea/\', \'<textarea placeholder="my place holder text" \', $html);
return $html;
}
但是,如果我删除
if ( \'event\' == $post->post_type )
从代码来看,它可以工作(但将应用于Wordpress上的每个html文本编辑器)。
知道我做错了什么吗?
最合适的回答,由SO网友:jockebq 整理而成
Solved it:
function add_placeholder_event( $html ){
$screen = get_current_screen();
$post_type = $screen->post_type;
if( $post_type == \'event\' ) {
$html = preg_replace(\'/<textarea/\', \'<textarea placeholder="John Doe" \', $html);
}
return $html;
}
add_filter(\'the_editor\',\'add_placeholder_event\');