enqueue.php
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Understrap enqueue scripts
*
* @package Understrap
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'understrap_scripts' ) ) {
/**
* Load theme's JavaScript and CSS sources.
*/
function understrap_scripts() {
// Get the theme data.
$the_theme = wp_get_theme();
$theme_version = $the_theme->get( 'Version' );
$bootstrap_version = get_theme_mod( 'understrap_bootstrap_version', 'bootstrap4' );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
// Grab asset urls.
$theme_styles = "/css/theme{$suffix}.css";
$theme_scripts = "/js/theme{$suffix}.js";
if ( 'bootstrap4' === $bootstrap_version ) {
$theme_styles = "/css/theme-bootstrap4{$suffix}.css";
$theme_scripts = "/js/theme-bootstrap4{$suffix}.js";
}
$css_version = $theme_version . '.' . filemtime( get_template_directory() . $theme_styles ); // @phpstan-ignore-line -- file exists
wp_enqueue_style( 'understrap-styles', get_template_directory_uri() . $theme_styles, array(), $css_version );
// Fix that the offcanvas close icon is hidden behind the admin bar.
if ( 'bootstrap4' !== $bootstrap_version && is_admin_bar_showing() ) {
understrap_offcanvas_admin_bar_inline_styles();
}
wp_enqueue_script( 'jquery' );
$js_version = $theme_version . '.' . filemtime( get_template_directory() . $theme_scripts ); // @phpstan-ignore-line -- file exists
wp_enqueue_script( 'understrap-scripts', get_template_directory_uri() . $theme_scripts, array(), $js_version, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
} // End of if function_exists( 'understrap_scripts' ).
add_action( 'wp_enqueue_scripts', 'understrap_scripts' );
if ( ! function_exists( 'understrap_offcanvas_admin_bar_inline_styles' ) ) {
/**
* Add inline styles for the offcanvas component if the admin bar is visibile.
*
* Fixes that the offcanvas close icon is hidden behind the admin bar.
*
* @since 1.2.0
*/
function understrap_offcanvas_admin_bar_inline_styles() {
$navbar_type = get_theme_mod( 'understrap_navbar_type', 'collapse' );
if ( 'offcanvas' !== $navbar_type ) {
return;
}
$css = '
body.admin-bar .offcanvas.show {
margin-top: 32px;
}
@media screen and ( max-width: 782px ) {
body.admin-bar .offcanvas.show {
margin-top: 46px;
}
}';
wp_add_inline_style( 'understrap-styles', $css );
}
}