The filter you’re after is tiny_mce_before_init
. Using this, we can hook into TinyMCE’s ‘init_array’ and add body classes:
add_filter( 'tiny_mce_before_init', 'wpse_235194_tiny_mce_classes' );
function wpse_235194_tiny_mce_classes( $init_array ){
global $post;
if( is_a( $post, 'WP_Post' ) ){
$init_array['body_class'] .= ' ' . join( ' ', get_post_class( '', $post->ID ) );
}
return $init_array;
}
We’re joining the post classes with a space to convert them from an array to a string as required by TinyMCE, and we’re also checking that we do actually have a valid post object, to avoid errors if you’re using TinyMCE elsewhere (such as in widgets or the like).
Related Posts:
- WordPress Visual Editor Stripping HTML Changes
- Add a class to links in the visual editor (how to get old dialog back)
- Shortcode to insert
- Detect a focus on wp_editor
- Load post content into iframe
- body_class filter – Is there a better way to write this code?
- Dynamically add styles to WP TinyMCE editor
- Adding dropdowns to the tinyMCE editor
- Page Reloads Before AJAX Request Finishes
- WordPress php filter admin_body_class not working
- Removing unneccessary p-tags (Not every p)
- Bridging TinyMCE js and WordPress PHP?
- Handling Body class based on Template
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- trigger html cleanup for all posts
- iframe does not store session/cookie when refresh parent
- Change tinyMCE editor to allow marked content when pasting from Word
- Need to put a script above tag in header.php – WP 5.7.1
- Add class to website based on post taxonomy
- what is the method to echo class attribute inside the i tag? [closed]
- How do I use an iFrame for my header in WordPress twenty seventeen?
- Include User ID in iFrame URL
- Using wp_editor() when not logged stopped working
- Adding body class to html tag that already has language attrubutes?
- Deny php execution in /wp-includes – using .htaccess in /wp-includes VS root folder
- load a wordpress page into another wordpress page using iframe
- How to load WP_Editor JS files manually (with AJAX)?
- Add php function into .js file (for tinyMCE button)
- WordPress TinyMCE Add Button To The Full Screen Mode Editor
- Trouble using wordpress functions in a pop-up modal form
- Replace TinyMCE with Custom Built Editor
- two body tags on all WP pages regardless of theme
- Change body_class() PAGE to HOME
- Is there a way to get wp_editor (tinymce) content?
- YouTube embeds Cross-Origin Request Blocked (CORB) error
- Limit Taxonomy Output in Conditional Statement
- Problem with AJAX in wordpress plugin
- WordPress archive page showing 404 Error [duplicate]
- wp_redirect only works on main site and not on other sites
- How to remove coupon dropdown feature
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Is it save to use eval for a jQuery callback method coming from the database?
- Division by zero error in image.php
- linking stylesheets and scripts with functions.php
- Jquery window.send_to_editor function
- PHP include statement not working?
- Code Executing Too Late?
- Double jQuery loaded
- PHP: Showing currency sign if input is a number
- Displaying text if post was within 5 hours
- New walker for walker_nav_menu to change inside container data
- load ajax using admin-ajax.php
- Create a WordPress shortcode using PHP [duplicate]
- Trying to prepend a Hashtag symbol to the_tags links [closed]
- What does -> mean in WordPress?
- Add data-id attribute to child page links
- WP_OPTIONS table, active_plugins entry [closed]
- Parsing Menu Items and Blog Posts
- Store post content in a php variable and output them using for loop
- Pagination on Custom Post
- Resize image to specific dimension (X to Y ratio)
- Fixing Memory Leaks in WordPress (HHVM)
- Writing PHP code in pages without issue?
- How to use theme function in post/page?
- Running rmdir function on post save
- Logic on a Gravity Forms redirect [closed]
- How to add div blocks after certain set of post
- How to pass a PHP $_GET variable and fetch/output it?
- how to disabled a button when press three times
- Get html data with javascript to php array and store to wordpress database
- Echo a shortcode div after every 3 posts
- Preg_Match(): compilation failed unknown property name
- Post images are not displayed on the front page
- do_action(), iFrame Gets Displayed Despite Password Protection [closed]
- $wpdb returns duplicate posts
- How to avoid duplicates when creating recent network posts
- esc_url( ) won’t use https
- Get all categories post is not in
- zip unzip attachments in wordpress
- php if username is role
- Function returns post URLs rather than retrieving Facebook Graph API data
- Ajax button not working
- Creating WordPress Shortcode with Variable
- Catchable fatal error: Object of class stdClass could not be converted to string
- Add shortcode in my div
- Get title attribute from galleries
- Syntax error in a shortcode function
- Execute a function every hour in the background
- How to add text to the start of all comments?
- If else statement to check for thumbnail and whether or not it’s a mobile device – streamline
- How can I display a div ONLY if it is not a certain term page
- Does anyone know all parameters of get_comments()
- Accessing $post after PHP is executed
- How can I automatically resize up images to fit into all of my registered image sizes
- Create page with custom php script and fetched data
- Next post link on a bootstrap button
- Flexslider won’t work on WordPress
- How to show an entire post content and not also the excerpt?
- How to overwrite orderby with add_query_var
- Does WordPress create a new Linux user when creating a new WordPress blog?