-
Notifications
You must be signed in to change notification settings - Fork 25
/
functions.php
305 lines (266 loc) · 8.63 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
/**
* Basic initialization for Mynote theme
*
* @author Terry Lin
* @link https://terryl.in/
*
* @package WordPress
* @subpackage Mynote
* @since 1.0.0
* @version 2.0.0
*/
if ( ! function_exists( 'mynote_setup_theme' ) ) {
function mynote_setup_theme() {
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// Add Thumbnail Theme Support.
add_theme_support( 'post-thumbnails' );
// Enables post and comment RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Custom Thumbnail Size call using the_post_thumbnail( 'mynote-thumbnail' ); .
add_image_size( 'mynote-thumbnail', 360, 240, true );
add_image_size( 'mynote-medium', 600, 400, true );
// Localisation Support.
load_theme_textdomain( 'mynote', get_template_directory() . '/languages' );
// Add excerpt to page.
add_post_type_support( 'page', 'excerpt' );
// Add custom background support.
$background_args = array(
'default-color' => '',
'default-image' => '',
'default-repeat' => 'repeat',
'default-position-x' => 'left',
'default-position-y' => 'top',
'default-size' => 'auto',
'default-attachment' => 'scroll',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
add_theme_support( 'custom-background', $background_args );
// Add theme support for Custom Header
$header_args = array(
'default-image' => '',
'width' => 1920,
'height' => 640,
'flex-width' => false,
'flex-height' => false,
'uploads' => true,
'random-default' => false,
'header-text' => true,
'default-text-color' => 'ffffff',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => '',
'video' => false,
'video-active-callback' => '',
);
add_theme_support( 'custom-header', $header_args );
// Add theme support for Custom Logo.
$logo_args = array(
'height' => 60,
'width' => 180,
'flex-width' => true,
);
add_theme_support( 'custom-logo', $logo_args );
add_theme_support(
'woocommerce',
array(
'thumbnail_image_width' => 150,
'single_image_width' => 300,
'product_grid' => array(
'default_rows' => 3,
'min_rows' => 2,
'max_rows' => 8,
'default_columns' => 4,
'min_columns' => 2,
'max_columns' => 5,
),
)
);
}
add_editor_style( 'editor-style.css' );
}
/**
* Add scripts
*/
function mynote_header_scripts() {
if ( 'wp-login.php' !== $GLOBALS['pagenow'] && ! is_admin() ) {
wp_register_script( 'bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.bundle.min.js', array( 'jquery' ), '4.1.0' );
wp_enqueue_script( 'bootstrap' );
}
}
/**
* Add styles
*/
function mynote_styles() {
wp_register_style( 'bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '4.1.0', 'all' );
wp_enqueue_style( 'bootstrap' );
wp_register_style( 'fontawesome', get_template_directory_uri() . '/assets/css/fontawesome-all.min.css', array(), '5.1.0', 'all' );
wp_enqueue_style( 'fontawesome' );
wp_register_style( 'mynote-font-roboto', 'https://fonts.googleapis.com/css?family=Roboto:300,400', array(), '1.0', 'all' );
wp_enqueue_style( 'mynote-font-roboto' );
wp_register_style( 'mynote', get_template_directory_uri() . '/style.css', array(), '2.0.3', 'all' );
wp_enqueue_style( 'mynote' );
}
/**
* Enqueue the javascript that performs in-link comment reply fanciness
*
* @return void
*/
function mynote_enqueue_comment_reply() {
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
/**
* Register mynote Navigation
*
* @return void
*/
function mynote_register_mynote_menu() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu', 'mynote' ),
'sidebar-menu' => __( 'Sidebar Menu', 'mynote' ),
'footer-menu' => __( 'Footer Menu', 'mynote' ),
'social' => __( 'Social Links Menu', 'mynote' ),
)
);
}
/**
* Register widget area.
*/
function mynote_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'mynote' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar on blog posts.', 'mynote' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Footer', 'mynote' ),
'id' => 'sidebar-2',
'description' => __( 'Add widgets here to appear in your footer.', 'mynote' ),
'before_widget' => '<section id="%1$s" class="widget %2$s col-lg col-md-4 col-sm-12">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Sticky Sidebar', 'mynote' ),
'id' => 'sidebar-3',
'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'mynote' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Homepage Middle', 'mynote' ),
'id' => 'sidebar-4',
'description' => __( 'Add widgets here to appear in your homepage middle section.', 'mynote' ),
'before_widget' => '<section id="%1$s" class="widget %2$s col-lg col-md-4 col-sm-12">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Homepage Intro', 'mynote' ),
'id' => 'sidebar-5',
'description' => __( 'Add widgets here to appear in your homepage intro section.', 'mynote' ),
'before_widget' => '<section id="%1$s" class="widget %2$s my-2 col-lg-12">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Homepage Sidebar', 'mynote' ),
'id' => 'sidebar-6',
'description' => __( 'Add widgets here to appear in your sidebar on homepage.', 'mynote' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Archive Sidebar', 'mynote' ),
'id' => 'sidebar-7',
'description' => __( 'Add widgets here to appear in your sidebar on archive pages.', 'mynote' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_widget( 'Mynote_Widget_Toc' );
}
// I still don't know why should I put this line to ignore theme-check warning.
if ( ! isset( $content_width ) ) {
$content_width = 900;
}
if ( ! function_exists( 'wp_body_open' ) ) {
/**
* Added for backwards compatibility to support WordPress versions prior to 5.2.0.
*
* @since WP 5.2.0
*/
function wp_body_open() {
do_action( 'wp_body_open' );
}
}
/**
* Customizer additions.
*/
if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) {
require get_parent_theme_file_path( '/inc/customizer.php' );
}
/**
* Implement the Custom Header feature.
*/
require get_parent_theme_file_path( '/inc/customize-css.php' );
/**
* Custom Walker_Nav_Menu for Mynote theme header menu.
*/
require get_parent_theme_file_path( '/inc/classes/navbar/class-mynote-walker.php' );
/**
* Sticky TOC widget for single post.
*/
require get_parent_theme_file_path( '/inc/classes/widgets/class-mynote-widget-toc.php' );
/**
* Custom template tags for this theme.
*/
require get_parent_theme_file_path( '/inc/template-tags.php' );
/**
* Additional features to allow styling of the templates.
*/
require get_parent_theme_file_path( '/inc/template-functions.php' );
/**
* Social icon functions.
*/
require get_parent_theme_file_path( '/inc/icon-functions.php' );
/**
* Mynote template functions for hooks.
*/
require get_parent_theme_file_path( '/inc/template-hook-functions.php' );
/**
* Hooks for Mynote theme.
*/
require get_parent_theme_file_path( '/inc/template-hooks.php' );