I would like to get html class names same way get_body_class() works but on the admin side. I would like to change body class names of TinyMCEs iFrame element to allow specified editor-styles.css styles work only when editing page with .page and .home classes.

Styles:

body.page.home table td:nth-child(2) {
    padding-left:30px;
}

This is not working:

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

    //var_dump(get_option( 'page_on_front'));
    //var_dump(get_option('show_on_front'));
    if (is_front_page()) {
        $init_array['body_class'][] = 'home';
    }
    if (is_page()) {
        $init_array['body_class'][] = 'page';
    }
    if (isset($init_array['body_class']) && is_array($init_array['body_class'])) {
        $init_array['body_class'] = implode(' ', $init_array['body_class']);
    }
}

In other words:

How to specify custom editor-styles for TinyMCE for just one exact page (in my case it is home page).

1 Answer
1

If I understand you correctly, you want a custom editor style when editing the homepage? You can check if you’re currently editing the homepage by comparing the post ID to the ID in the page_on_front option, like this:

function homepage_editor_styles() {
    global $post_ID, $post_type;

    if ( empty ( $post_ID ) || 'page' !== $post_type )
        return;
    if ( $post_ID === (int) get_option( 'page_on_front' ) ) {
        add_editor_style( 'css/editor-style-homepage.css' );
    }
}
add_action('admin_head', 'homepage_editor_styles');

Leave a Reply

Your email address will not be published. Required fields are marked *