{"id":165,"date":"2019-10-24T08:52:58","date_gmt":"2019-10-24T07:52:58","guid":{"rendered":"https:\/\/www.freelancewp.guide\/?p=165"},"modified":"2022-07-28T07:59:56","modified_gmt":"2022-07-28T07:59:56","slug":"add-cache-version-number-to-editor-style-css","status":"publish","type":"post","link":"https:\/\/freelancewp.guide\/add-cache-version-number-to-editor-style-css\/","title":{"rendered":"Add Cache Version Number to editor-style.css"},"content":{"rendered":"\n

You can add a custom style sheet to format the WordPress editor using add_editor_style<\/a>.<\/p>\n\n\n\n

A frustrating problem with this technique is that browsers will typically cache this css file pretty hard, and so it’s tricky to see that changes you made appear in the editor.<\/p>\n\n\n\n

This is how you would typically add a custom style sheet.<\/p>\n\n\n\n

add_editor_style('editor-style.css');<\/code><\/pre>\n\n\n\n

Add the code below to you theme’s functions.php file and the editor-style.css will be given a version number that changes each time the file is saved, and avoiding any caching issues.<\/p>\n\n\n\n

\/\/ Change cache suffix on editor-style.css\nfunction my_tiny_mce_before_init( $mce_init ) {\n\n  \/\/ Get the timestamp of the file  \n  $time = filemtime(get_template_directory().'\/editor-style.css');\n\n  \/\/ Add the timestamp  \n  $mce_init['cache_suffix'] = 'v='.$time;\n\n  return $mce_init;\n}\nadd_filter( 'tiny_mce_before_init', 'my_tiny_mce_before_init' );<\/code><\/pre>\n\n\n\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

You can add a custom style sheet to format the WordPress editor using add_editor_style. A frustrating problem with this technique is that browsers will typically cache this css file pretty hard, and so it’s tricky to see that changes you made appear in the editor. This is how you would typically add a custom style […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/posts\/165"}],"collection":[{"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/comments?post=165"}],"version-history":[{"count":1,"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":833,"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/posts\/165\/revisions\/833"}],"wp:attachment":[{"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/media?parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/categories?post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freelancewp.guide\/wp-json\/wp\/v2\/tags?post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}