-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
342 lines (284 loc) · 12 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?php
/**
* GT Modern functions and definitions
*
* @package GT Modern
*/
/**
* GT Modern only works in WordPress 5.3 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '5.3', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function gt_modern_setup() {
// Make theme available for translation.
load_theme_textdomain( 'gt-modern', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// Enable support for Post Thumbnails on posts and pages.
add_theme_support( 'post-thumbnails' );
// Set default Post Thumbnail size.
set_post_thumbnail_size( 1600, 900, true );
// Add image size for header image on single posts and pages.
add_image_size( 'gt-modern-header-image', 9999, 640, true );
// Register Navigation Menus.
register_nav_menus( array(
'primary' => esc_html__( 'Main Navigation', 'gt-modern' ),
'footer' => esc_html__( 'Footer Navigation', 'gt-modern' ),
'social-header' => esc_html__( 'Social Icons (Header)', 'gt-modern' ),
'social-footer' => esc_html__( 'Social Icons (Footer)', 'gt-modern' ),
) );
// Switch default core markup for galleries and captions to output valid HTML5.
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Set up the WordPress core custom logo feature.
add_theme_support( 'custom-logo', apply_filters( 'gt_modern_custom_logo_args', array(
'height' => 60,
'width' => 300,
'flex-height' => true,
'flex-width' => true,
) ) );
// Set up the WordPress core custom header feature.
add_theme_support( 'custom-header', apply_filters( 'gt_modern_custom_header_args', array(
'header-text' => false,
'width' => 9999,
'height' => 640,
) ) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'gt_modern_custom_background_args', array(
'default-color' => 'cccccc',
) ) );
// Add Theme Support for Selective Refresh in Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
add_action( 'after_setup_theme', 'gt_modern_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function gt_modern_content_width() {
// Set global variable for content width.
$GLOBALS['content_width'] = apply_filters( 'gt_modern_content_width', 800 );
}
add_action( 'after_setup_theme', 'gt_modern_content_width', 0 );
/**
* Enqueue scripts and styles.
*/
function gt_modern_scripts() {
// Get Theme Version.
$theme_version = wp_get_theme()->get( 'Version' );
// Register and Enqueue Stylesheet.
wp_enqueue_style( 'gt-modern-stylesheet', get_stylesheet_uri(), array(), $theme_version );
// Register and enqueue navigation.js.
if ( has_nav_menu( 'primary' ) or has_nav_menu( 'social-header' ) ) {
wp_enqueue_script( 'gt-modern-navigation', get_theme_file_uri( '/assets/js/navigation.min.js' ), array( 'jquery' ), '20200911', true );
$gt_modern_l10n = array(
'expand' => esc_html__( 'Expand child menu', 'gt-modern' ),
'collapse' => esc_html__( 'Collapse child menu', 'gt-modern' ),
'icon' => gt_modern_get_svg( 'expand' ),
);
wp_localize_script( 'gt-modern-navigation', 'gtModernScreenReaderText', $gt_modern_l10n );
}
// Register and enqueue header-search.js if enabled
if ( true === gt_modern_get_option( 'header_search' ) || is_customize_preview() ) :
wp_enqueue_script( 'gt-modern-header-search', get_theme_file_uri( '/assets/js/header-search.min.js' ), array( 'jquery' ), '20200911', true );
endif;
// Register and enqueue scroll-to-top.js if enabled
if ( true === gt_modern_get_option( 'scroll_to_top' ) || is_customize_preview() ) :
wp_enqueue_script( 'gt-modern-scroll-to-top', get_theme_file_uri( '/assets/js/scroll-to-top.min.js' ), array( 'jquery' ), '20210408', true );
wp_localize_script( 'gt-modern-scroll-to-top', 'gtModernScrollButton', array( 'icon' => gt_modern_get_svg( 'collapse' ) ) );
endif;
// Enqueue svgxuse to support external SVG Sprites in Internet Explorer.
wp_enqueue_script( 'svgxuse', get_theme_file_uri( '/assets/js/svgxuse.min.js' ), array(), '1.2.4' );
// Register Comment Reply Script for Threaded Comments.
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'gt_modern_scripts' );
/**
* Enqueue theme fonts.
*/
function gt_modern_theme_fonts() {
$fonts_url = gt_modern_get_fonts_url();
// Load Fonts if necessary.
if ( $fonts_url ) {
require_once get_theme_file_path( 'inc/wptt-webfont-loader.php' );
wp_enqueue_style( 'gt-modern-theme-fonts', wptt_get_webfont_url( $fonts_url ), array(), '20210105' );
}
}
add_action( 'wp_enqueue_scripts', 'gt_modern_theme_fonts', 1 );
add_action( 'enqueue_block_editor_assets', 'gt_modern_theme_fonts', 1 );
/**
* Retrieve webfont URL to load fonts locally.
*/
function gt_modern_get_fonts_url() {
$font_families = array(
'Barlow:400,400italic,700,700italic',
);
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
'display' => urlencode( 'swap' ),
);
return apply_filters( 'gt_modern_get_fonts_url', add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ) );
}
/**
* Register widget areas and custom widgets.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function gt_modern_widgets_init() {
// Register Blog Sidebar widget area.
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'gt-modern' ),
'id' => 'sidebar-1',
'description' => esc_html_x( 'Appears on blog pages and single posts.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Register Before Header widget area.
register_sidebar( array(
'name' => esc_html__( 'Before Header', 'gt-modern' ),
'id' => 'before-header',
'description' => esc_html_x( 'Appears above the header area.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Register After Header widget area.
register_sidebar( array(
'name' => esc_html__( 'After Header', 'gt-modern' ),
'id' => 'after-header',
'description' => esc_html_x( 'Appears below the header area.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Register Before Blog widget area.
register_sidebar( array(
'name' => esc_html__( 'Before Content', 'gt-modern' ),
'id' => 'before-content',
'description' => esc_html_x( 'Appears above the content area.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Register After Posts widget area.
register_sidebar( array(
'name' => esc_html__( 'After Single Posts', 'gt-modern' ),
'id' => 'after-posts',
'description' => esc_html_x( 'Appears below single posts.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Register After Pages widget area.
register_sidebar( array(
'name' => esc_html__( 'After Pages', 'gt-modern' ),
'id' => 'after-pages',
'description' => esc_html_x( 'Appears below static pages.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Register Before Footer widget area.
register_sidebar( array(
'name' => esc_html__( 'Before Footer', 'gt-modern' ),
'id' => 'before-footer',
'description' => esc_html_x( 'Appears above the footer area.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Register Footer Column 1 widget area.
register_sidebar( array(
'name' => esc_html__( 'Footer Column 1', 'gt-modern' ),
'id' => 'footer-column-1',
'description' => esc_html_x( 'Appears in the first column in footer.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
// Register Footer Column 2 widget area.
register_sidebar( array(
'name' => esc_html__( 'Footer Column 2', 'gt-modern' ),
'id' => 'footer-column-2',
'description' => esc_html_x( 'Appears in the second column in footer.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
// Register Footer Column 3 widget area.
register_sidebar( array(
'name' => esc_html__( 'Footer Column 3', 'gt-modern' ),
'id' => 'footer-column-3',
'description' => esc_html_x( 'Appears in the third column in footer.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
// Register Footer Column 4 widget area.
register_sidebar( array(
'name' => esc_html__( 'Footer Column 4', 'gt-modern' ),
'id' => 'footer-column-4',
'description' => esc_html_x( 'Appears in the fourth column in footer.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
// Register Footer Copyright widget area.
register_sidebar( array(
'name' => esc_html__( 'Footer Copyright', 'gt-modern' ),
'id' => 'footer-copyright',
'description' => esc_html_x( 'Appears in the bottom footer line.', 'widget area description', 'gt-modern' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
}
add_action( 'widgets_init', 'gt_modern_widgets_init' );
/**
* Include Files
*/
// Include Customizer Options.
require get_template_directory() . '/inc/customizer/customizer.php';
require get_template_directory() . '/inc/customizer/default-options.php';
// Include Template Functions.
require get_template_directory() . '/inc/template-functions.php';
// Include Template Tags.
require get_template_directory() . '/inc/template-tags.php';
// Include Gutenberg Features.
require get_template_directory() . '/inc/gutenberg.php';
// Include Customization Features.
require get_template_directory() . '/inc/custom-colors.php';
require get_template_directory() . '/inc/custom-fonts.php';