0

Can't seem to find any valuable info on this at the moment - I just want to resize the height of the classic editor field for my Custom Post types.

I was hoping to just drop a function or code snippet into functions.php for this, if possible?

In this example I would have 3 Custom Post types: 'Tools', 'Brand' and 'Company' and for all three I would like the editor to only be about a qtr of its height or about 120px tall or 8 lines.

Many thanks for any help in on this!

2

One way is to adjust the TinyMCE settings:

add_filter( 'tiny_mce_before_init', function( $settings ) {
    $settings['height'] = '120';
    $settings['autoresize_max_height'] = '120';
    return $settings;   
} );

and e.g. restrict further on post types and !block editor with get_current_screen().

Example:

add_filter( 'tiny_mce_before_init', function( $settings ) {

    $screen = get_current_screen();

    if ( $screen->is_block_editor() ) {
        return $settings;
    }        

    if ( ! in_array( $screen->post_type, ['tools', 'brand', 'company'], true ) ) {
        return $settings;
    }        

    $settings['height'] = '120';
    $settings['autoresize_max_height'] = '120';

    return $settings;
 } );
8
  • Thanks for the tip, I am so new to PHP the get current screen is a bit over my head, would you mind editing your answer to include this for post types: 'Tools', 'Brand' and 'Company' ? I did paste your code into functions.php with no success. (I am building a custom-theme)
    – ShrockCo
    Jul 23 at 20:06
  • Works on my install with Classic Editor. Try e.g. $screen = get_current_screen(); and then wrap settings with if ( ! $screen->is_block_editor() && in_array( $screen->post_type, ['tools', 'brand', 'company'], true ) ) { ...settings here ... }. Note that body class is also inside $settings['body_class'].
    – birgire
    Jul 23 at 20:28
  • I tried but its now throwing Fatal error: Uncaught Error: Call to undefined function get_current_screen() Here it is on pastebin I probably don't have something correct yet. ~ Appreciate your help!
    – ShrockCo
    Jul 23 at 22:29
  • it goes into the function, not outside it, and no endif;
    – birgire
    Jul 23 at 23:23
  • 1
    Very grateful - Thanks a million!
    – ShrockCo
    Jul 24 at 15:12
1

You can insert custom style in the WP admin section via admin_head action hook.

function wp123_set_editor_height() {
  ?>
  <style type="text/css">
    /* For PAGE post type */
    body.post-type-page #postdivrich #wp-content-editor-container iframe {
      height:  120px !important;
    }
  </style>
  <?php
}
add_action( 'admin_head', 'wp123_set_editor_height' );

Say for example your custom post type is "sample" then you have to target the body as follows:

body.post-type-sample

1
  • Thanks for the tip, so I pasted that into my functions.php following your instructions, but nothing worked?
    – ShrockCo
    Jul 23 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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