Skip to content

Instantly share code, notes, and snippets.

@koohz
Last active December 5, 2016 18:21
Show Gist options
  • Save koohz/95aaaab08fe22f1e2dc92c71b593d6a1 to your computer and use it in GitHub Desktop.
Save koohz/95aaaab08fe22f1e2dc92c71b593d6a1 to your computer and use it in GitHub Desktop.
Reload Styles in Wordpress Customizer Preview
add_action('customize_controls_print_footer_scripts', function(){?>
<script type="text/javascript">
( function ( wp, $ ) {
console.log($("#save"))
var btn = $("<button style='margin-right: 5px' class='button button-primary'>Reload CSS</button>").click(function(e){
e.preventDefault(true);
wp.customize.previewer.preview.iframe.get(0).contentWindow.reloadStylesheets();
});
$("#save").after(btn);
})( window.wp, jQuery );
</script>
<?php }, 9999);
if(is_customize_preview())
{
add_action('wp_footer', function(){ ?>
<script type="text/javascript">
function reloadStylesheets() {
var queryString = '?reload=' + new Date().getTime();
jQuery('link[rel="stylesheet"]').each(function () {
this.href = this.href.replace(/\?.*|$/, queryString);
});
}
</script>
<?php
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment