How can we apply filters only to posts with a specific custom post type? I would like some of my custom posts to start out in HTML mode for their editors. This is what I am working with so far…
add_filter( 'wp_default_editor', create_function('', 'return "html";') );
2 Answers
You can determine the current post type using get_post_type()
inside the callback function hooked to wp_default_editor
:
add_filter( 'wp_default_editor', 'wpse242896_wp_default_editor' );
function wpse242896_wp_default_editor( $editor ) {
$post_type = get_post_type();
if ( 'custom_post_type' === $post_type ) {
return 'html';
} else if ( 'other_post_type' === $post_type ) {
return 'tinymce';
}
return $editor;
}
Also, anonymous functions are generally discouraged because they can’t be unhooked very easily.