Our current workaround solution to remove Corerstone’s linked CSS and, at the same time, keep Cornerstone inline styles :
function stb_cornerstone_remove_styles() {
add_filter( 'cornerstone_enqueue_styles', '__return_false' );
}
add_filter( 'after_setup_theme', 'stb_cornerstone_remove_styles' );
function stb_enqueue_styles_and_scripts() {
global $wp_styles;
// Copy and insert inline overrun CSS from Cornerstone
// Check if Cornerstone Style Exists
if ( !empty( $wp_styles->registered[ 'cs' ] ) ) {
// Check if Cornerstone Inline Styles Exists
if ( !empty( $wp_styles->registered[ 'cs' ]->extra ) ) {
// Create dummy handle
wp_register_style( 'stb-cs', false );
wp_enqueue_style( 'stb-cs' );
// Copy Cornerstone Inline CSS over to the "dummy" stb-cs
$wp_styles->registered[ 'stb-cs' ]->extra = $wp_styles->registered[ 'cs' ]->extra;
// Let's make sure original Cornerstone linked CSS does not get outputted and,
// at the same time CS Back-End editor WILL show real-time/WYSIWYG changes made in the editor
$wp_styles->registered[ 'cs' ]->src = false;
}
// Remove URI so, linked CSS will not be inserted in Front-End and, at the same time
// realtime/WYSIWYG styling in the Back-End CS Editor will still work
// (its using inlined styles attached to 'cs' style which should not be removed)
$wp_styles->registered[ 'cs' ]->src = false;
}
}
add_action( 'wp_enqueue_scripts', 'stb_enqueue_styles_and_scripts', 9999 );
function stb_cornerstone_remove_css_scripts() {
if ( !function_exists( 'CS' ) ) return;
// Remove Cornerstone linked CSS
wp_dequeue_style( 'cs' );
//wp_deregister_style('cs'); //NOTE: If 'cs' is deregistered Cornerstone Back-End editor will NOT show changes made in the editor
}
add_action( 'wp_enqueue_scripts', 'stb_cornerstone_remove_css_scripts', 99999 );
It feels hackish and error-prone since one day you will probably change something that will break this, so it would be great and developer friendly if there would be separated hooks with which, we could control which CSS (linked and/or inlined) we would like to remove.
E.g.:
- 'cornerstone_enqueue_styles’ / 'cornerstone_enqueue_styles_linked’
- 'cornerstone_enqueue_styles_inline’
Do you have a hook like that? Could you provide it?
Kind regards.
PS: The same goes for Cornerstone scripts.