Skip to content

Commit 8218ba6

Browse files
committed
Conditionally include styles
1 parent 1eaeca5 commit 8218ba6

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

includes/public/public.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ function wzkb_lang_init() {
3434
function wpkb_enqueue_styles() {
3535

3636
wp_register_style( 'wzkb_styles', WZKB_PLUGIN_URL . 'includes/public/css/wzkb-styles.min.css', array( 'dashicons' ), '1.0' );
37-
if ( wzkb_get_option( 'include_styles' ) ) {
38-
wp_enqueue_style( 'wzkb_styles' );
37+
38+
if ( is_singular() ) {
39+
$id = get_the_ID();
40+
if ( has_block( 'knowledgebase/knowledgebase', $id ) && wzkb_get_option( 'include_styles' ) ) {
41+
wp_enqueue_style( 'wzkb_styles' );
42+
}
3943
}
4044

4145
wp_add_inline_style( 'wzkb_styles', esc_html( wzkb_get_option( 'custom_css' ) ) );
@@ -44,13 +48,6 @@ function wpkb_enqueue_styles() {
4448
$extra_styles = '#wzkb-sidebar-primary{width:25%;}#wzkb-content-primary{width:75%;float:left;}';
4549
wp_add_inline_style( 'wzkb_styles', $extra_styles );
4650
}
47-
48-
if ( is_singular() ) {
49-
$id = get_the_ID();
50-
if ( has_block( 'knowledgebase/knowledgebase', $id ) ) {
51-
wp_enqueue_style( 'wzkb_styles' );
52-
}
53-
}
5451
}
5552
add_action( 'wp_enqueue_scripts', 'wpkb_enqueue_styles' );
5653

includes/public/templates/archive-wz_knowledgebase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
/* This plugin uses the Archive file of TwentySeventeen theme as an example */
1717
get_header();
1818

19-
wp_enqueue_style( 'wzkb_styles' );
20-
19+
if ( wzkb_get_option( 'include_styles' ) ) {
20+
wp_enqueue_style( 'wzkb_styles' );
21+
}
2122
?>
2223
<div class="wrap">
2324
<div id="wzkb-content-primary" class="content-area">

includes/public/templates/single-wz_knowledgebase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
/* This plugin uses the Archive file of TwentySeventeen theme as an example */
1717
get_header();
1818

19-
wp_enqueue_style( 'wzkb_styles' );
20-
19+
if ( wzkb_get_option( 'include_styles' ) ) {
20+
wp_enqueue_style( 'wzkb_styles' );
21+
}
2122
?>
2223
<div class="wrap">
2324
<div id="wzkb-content-primary" class="content-area">

includes/public/templates/wzkb-search.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
/* This plugin uses the Archive file of TwentyFifteen theme as an example */
3333
get_header();
3434

35-
wp_enqueue_style( 'wzkb_styles' );
36-
35+
if ( wzkb_get_option( 'include_styles' ) ) {
36+
wp_enqueue_style( 'wzkb_styles' );
37+
}
3738
?>
3839
<div class="wrap">
3940
<div id="wzkb-content-primary" class="content-area">

includes/shortcode.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
*/
2727
function wzkb_shortcode( $atts, $content = null ) {
2828

29-
wp_enqueue_style( 'wzkb_styles' );
30-
wp_enqueue_style( 'dashicons' );
31-
29+
if ( wzkb_get_option( 'include_styles' ) ) {
30+
wp_enqueue_style( 'wzkb_styles' );
31+
}
3232
$atts = shortcode_atts(
3333
array(
3434
'category' => false,
@@ -135,7 +135,9 @@ function wzkb_shortcode_breadcrumb( $atts, $content = null ) {
135135
*/
136136
function wzkb_shortcode_alert( $atts, $content = null ) {
137137

138-
wp_enqueue_style( 'wzkb_styles' );
138+
if ( wzkb_get_option( 'include_styles' ) ) {
139+
wp_enqueue_style( 'wzkb_styles' );
140+
}
139141

140142
$atts = shortcode_atts(
141143
array(

0 commit comments

Comments
 (0)