1

I am trying to make a placeholder appear on the default html editor on a specific post type. The code looks like this:

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;
}

It does not work, however, if I remove if ( 'event' == $post->post_type ) from the code it will work (but will apply to every html text editor on Wordpress).

Any idea what I am doing wrong?

2
  • The editor is not a normal textarea. It is TinyMCE, and TinyMCE does not use a textarea. It's a HTML document in an iframe. Commented Mar 9, 2018 at 9:29
  • I have disabled the WYSIWYG/TinyMCE editor, and using only the standard html/text editor for this post type. Or what do you mean? It does work for me, I just can't make it only apply to a custom post type?
    – jockebq
    Commented Mar 9, 2018 at 9:31

1 Answer 1

3

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.