-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
119 lines (109 loc) · 3.46 KB
/
functions.php
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
<?php
declare(strict_types=1);
/**
* Project: wordpress-skeleton-theme
*
* @author Thilo Ratnaweera <thilo.ratnaweera@netbrothers.de>
* @copyright 2024 NetBrothers GmbH
* @license GPLv3
*/
/**
* Add scripts and styles.
* @return void
*/
function nb_add_theme_scripts()
{
// add global style
wp_enqueue_style('nb_style', get_stylesheet_uri());
// add additional style
// wp_enqueue_style('nb_slider', get_template_directory_uri() . '/css/slider.css', [], '1.1', 'all');
// add global script
wp_enqueue_script(
'nb_script',
get_template_directory_uri() . '/js/script.js',
// dependencies
[],
// version (increase on changes)
'1.0.0',
// options (optional obviously)
[
'in_footer' => true, // or false
'strategy' => 'async', // or 'defer'
]
);
// @see https://developer.wordpress.org/themes/basics/including-css-javascript/#the-comment-reply-script
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'nb_add_theme_scripts');
/**
* Register menus
* @return void
*/
function nb_register_menus()
{
register_nav_menus([
'nb-main-menu' => __('Main Menu', 'nb-wordpress-skeleton-theme'),
'nb-cta-menu' => __('Call-to-Action Menu', 'nb-wordpress-skeleton-theme'),
]);
}
add_action( 'init', 'nb_register_menus' );
/**
* Register sidebar, widget areas, etc.
* @return void
*/
function nb_register_widget_areas()
{
register_sidebar([
'name' => __('Sidebar', 'nb-wordpress-skeleton-theme'),
'id' => 'sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
]);
// for ($i = 1; $i <= 4; $i++) {
// register_sidebar([
// 'name' => __(sprintf('Footer Widget Area %d', $i), 'nb-wordpress-skeleton-theme'),
// 'id' => 'sidebar-2',
// 'before_widget' => '<ul><li id="%1$s" class="widget %2$s">',
// 'after_widget' => '</li></ul>',
// 'before_title' => '<h3 class="widget-title">',
// 'after_title' => '</h3>',
// ]);
// }
}
add_action('widgets_init', 'nb_register_widget_areas');
/**
* Theme Settings
*
* @param mixed $wp_customize
* @return void
*/
function nb_customize_register($wp_customize)
{
// section in customizer
$wp_customize->add_section('nb_theme_settings_section', [
'title' => __('Additional Theme Settings', 'nb-wordpress-skeleton-theme'),
]);
// copyright setting
$wp_customize->add_setting('nb_theme_setting_copyright', [
// @see https://www.usablewp.com/learn-wordpress/wordpress-customizer/theme-mods-vs-options-in-wordpress/
'type' => 'option',
]);
// control to change copyright setting
$wp_customize->add_control(new WP_Customize_Control(
$wp_customize,
'nb_theme_control_copyright',
[
'label' => __('Copyright', 'nb-wordpress-skeleton-theme'),
'section' => 'nb_theme_settings_section',
'settings' => [
'nb_theme_setting_copyright',
// ... add any additional settings IDs ...
],
]
));
}
add_action('customize_register', 'nb_customize_register');