functions.php
3.12 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Understrap Child Theme functions and definitions
*
* @package UnderstrapChild
*/
// Exit if accessed directly.
defined('ABSPATH') || exit;
include 'inc/blocks.php';
/**
* Removes the parent themes stylesheet and scripts from inc/enqueue.php
*/
function understrap_remove_scripts()
{
wp_dequeue_style('understrap-styles');
wp_deregister_style('understrap-styles');
wp_dequeue_script('understrap-scripts');
wp_deregister_script('understrap-scripts');
}
add_action('wp_enqueue_scripts', 'understrap_remove_scripts', 20);
/**
* Enqueue our stylesheet and javascript file
*/
function theme_enqueue_styles()
{
// Get the theme data.
$the_theme = wp_get_theme();
$theme_version = $the_theme->get('Version');
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
// Grab asset urls.
$theme_styles = "/css/child-theme{$suffix}.css";
$theme_scripts = "/js/child-theme{$suffix}.js";
$css_version = $theme_version . '.' . filemtime(get_stylesheet_directory() . $theme_styles);
wp_enqueue_style('child-understrap-styles', get_stylesheet_directory_uri() . $theme_styles, array(), $css_version);
wp_enqueue_script('jquery');
$js_version = $theme_version . '.' . filemtime(get_stylesheet_directory() . $theme_scripts);
wp_enqueue_script('child-understrap-scripts', get_stylesheet_directory_uri() . $theme_scripts, array(), $js_version, true);
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
/**
* Load the child theme's text domain
*/
function add_child_theme_textdomain()
{
load_child_theme_textdomain('understrap-child', get_stylesheet_directory() . '/languages');
}
add_action('after_setup_theme', 'add_child_theme_textdomain');
/**
* Overrides the theme_mod to default to Bootstrap 5
*
* This function uses the `theme_mod_{$name}` hook and
* can be duplicated to override other theme settings.
*
* @return string
*/
function understrap_default_bootstrap_version()
{
return 'bootstrap5';
}
add_filter('theme_mod_understrap_bootstrap_version', 'understrap_default_bootstrap_version', 20);
function my_custom_menus()
{
register_nav_menus(
array(
'top' => __('Top Menu', 'understrap'),
)
);
}
add_action('init', 'my_custom_menus');
/**
* Loads javascript for showing customizer warning dialog.
*/
function understrap_child_customize_controls_js()
{
wp_enqueue_script(
'understrap_child_customizer',
get_stylesheet_directory_uri() . '/js/customizer-controls.js',
array('customize-preview'),
'20130508',
true
);
}
add_action('customize_controls_enqueue_scripts', 'understrap_child_customize_controls_js');
function upload_svg_files($allowed)
{
if (!current_user_can('manage_options'))
return $allowed;
$allowed['svg'] = 'image/svg+xml';
return $allowed;
}
add_filter('upload_mimes', 'upload_svg_files');
function print_menu_shortcode($atts, $content = null) {
extract(shortcode_atts(array( 'name' => null, 'class' => null ), $atts));
return wp_nav_menu( array( 'menu' => $name, 'menu_class' => $class, 'echo' => false ) );
}
add_shortcode('menu', 'print_menu_shortcode');