Last active
December 5, 2016 18:21
-
-
Save koohz/95aaaab08fe22f1e2dc92c71b593d6a1 to your computer and use it in GitHub Desktop.
Reload Styles in Wordpress Customizer Preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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