Skip to content

Instantly share code, notes, and snippets.

@binzorellino
Created November 22, 2019 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binzorellino/5de940c61b82609613d26316ff972ecb to your computer and use it in GitHub Desktop.
Save binzorellino/5de940c61b82609613d26316ff972ecb to your computer and use it in GitHub Desktop.
Wordpress - force to refresh the cached TinyMCE editor style css file
<?php
add_filter( 'mce_css', 'fresh_editor_style' );
function fresh_editor_style( $css ) {
global $editor_styles;
if ( empty ( $css ) or empty ( $editor_styles ) ) {
return $css;
}
$mce_css = array();
$style_uri = get_stylesheet_directory_uri();
$style_dir = get_stylesheet_directory();
if ( is_child_theme() ) {
$template_uri = get_template_directory_uri();
$template_dir = get_template_directory();
foreach ( $editor_styles as $key => $file ) {
if ( $file && file_exists( "$template_dir/$file" ) ) {
$mce_css[] = add_query_arg(
'version',
filemtime( "$template_dir/$file" ),
"$template_uri/$file"
);
}
}
}
foreach ( $editor_styles as $file ) {
if ( $file && file_exists( "$style_dir/$file" ) ) {
$mce_css[] = add_query_arg(
'version',
filemtime( "$style_dir/$file" ),
"$style_uri/$file"
);
}
}
return implode( ',', $mce_css );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment