-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
294 lines (238 loc) · 9.87 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
<?php
/**
* Maxwell functions and definitions
*
* @package Maxwell
*/
/**
* Maxwell only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
if ( ! function_exists( 'maxwell_setup' ) ) :
/**
* 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 maxwell_setup() {
// Make theme available for translation. Translations can be filed in the /languages/ directory.
load_theme_textdomain( 'maxwell', 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 detfault Post Thumbnail size.
set_post_thumbnail_size( 850, 550, true );
// Register Navigation Menu.
register_nav_menu( 'primary', esc_html__( 'Main Navigation', 'maxwell' ) );
// Switch default core markup for search form, comment form, and comments to output valid HTML5.
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'maxwell_custom_background_args', array( 'default-color' => '303030' ) ) );
// Set up the WordPress core custom logo feature.
add_theme_support( 'custom-logo', apply_filters( 'maxwell_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( 'maxwell_custom_header_args', array(
'header-text' => false,
'width' => 1200,
'height' => 400,
'flex-height' => true,
) ) );
// Add Theme Support for wooCommerce.
add_theme_support( 'woocommerce' );
// Add extra theme styling to the visual editor.
add_editor_style( array( 'assets/css/editor-style.css', get_template_directory_uri() . '/assets/css/custom-fonts.css' ) );
// Add Theme Support for Selective Refresh in Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
// Add custom color palette for Gutenberg.
add_theme_support( 'editor-color-palette', array(
array(
'name' => esc_html_x( 'Primary', 'Gutenberg Color Palette', 'maxwell' ),
'slug' => 'primary',
'color' => apply_filters( 'maxwell_primary_color', '#33bbcc' ),
),
array(
'name' => esc_html_x( 'White', 'Gutenberg Color Palette', 'maxwell' ),
'slug' => 'white',
'color' => '#ffffff',
),
array(
'name' => esc_html_x( 'Light Gray', 'Gutenberg Color Palette', 'maxwell' ),
'slug' => 'light-gray',
'color' => '#f0f0f0',
),
array(
'name' => esc_html_x( 'Dark Gray', 'Gutenberg Color Palette', 'maxwell' ),
'slug' => 'dark-gray',
'color' => '#777777',
),
array(
'name' => esc_html_x( 'Black', 'Gutenberg Color Palette', 'maxwell' ),
'slug' => 'black',
'color' => '#303030',
),
) );
// Add support for responsive embed blocks.
add_theme_support( 'responsive-embeds' );
}
endif;
add_action( 'after_setup_theme', 'maxwell_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 maxwell_content_width() {
$GLOBALS['content_width'] = apply_filters( 'maxwell_content_width', 810 );
}
add_action( 'after_setup_theme', 'maxwell_content_width', 0 );
/**
* Register widget areas and custom widgets.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function maxwell_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'maxwell' ),
'id' => 'sidebar',
'description' => esc_html__( 'Appears on posts and pages except the full width template.', 'maxwell' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
'after_widget' => '</aside>',
'before_title' => '<div class="widget-header"><h3 class="widget-title">',
'after_title' => '</h3></div>',
) );
register_sidebar( array(
'name' => esc_html__( 'Header', 'maxwell' ),
'id' => 'header',
'description' => esc_html__( 'Appears on header area. You can use a search or ad widget here.', 'maxwell' ),
'before_widget' => '<aside id="%1$s" class="header-widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h4 class="header-widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Magazine Homepage', 'maxwell' ),
'id' => 'magazine-homepage',
'description' => esc_html__( 'Appears on blog index and Magazine Homepage template. You can use the Magazine widgets here.', 'maxwell' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget-header"><h3 class="widget-title">',
'after_title' => '</h3></div>',
) );
}
add_action( 'widgets_init', 'maxwell_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function maxwell_scripts() {
// Get Theme Version.
$theme_version = wp_get_theme()->get( 'Version' );
// Register and Enqueue Stylesheet.
wp_enqueue_style( 'maxwell-stylesheet', get_stylesheet_uri(), array(), $theme_version );
// Register and Enqueue Safari Flexbox CSS fixes.
wp_enqueue_style( 'maxwell-safari-flexbox-fixes', get_template_directory_uri() . '/assets/css/safari-flexbox-fixes.css', array(), '20200827' );
// Register Genericons.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/assets/genericons/genericons.css', array(), '3.4.1' );
// Register and Enqueue HTML5shiv to support HTML5 elements in older IE versions.
wp_enqueue_script( 'html5shiv', get_template_directory_uri() . '/assets/js/html5shiv.min.js', array(), '3.7.3' );
wp_script_add_data( 'html5shiv', 'conditional', 'lt IE 9' );
// Register and enqueue navigation.js.
if ( ( has_nav_menu( 'primary' ) || has_nav_menu( 'secondary' ) ) && ! maxwell_is_amp() ) {
wp_enqueue_script( 'maxwell-navigation', get_theme_file_uri( '/assets/js/navigation.min.js' ), array( 'jquery' ), '20200822', true );
$maxwell_l10n = array(
'expand' => esc_html__( 'Expand child menu', 'maxwell' ),
'collapse' => esc_html__( 'Collapse child menu', 'maxwell' ),
'icon' => maxwell_get_svg( 'expand' ),
);
wp_localize_script( 'maxwell-navigation', 'maxwellScreenReaderText', $maxwell_l10n );
}
// Enqueue svgxuse to support external SVG Sprites in Internet Explorer.
if ( ! maxwell_is_amp() ) {
wp_enqueue_script( 'svgxuse', get_theme_file_uri( '/assets/js/svgxuse.min.js' ), array(), '1.2.6' );
}
// 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', 'maxwell_scripts' );
/**
* Enqueue custom fonts.
*/
function maxwell_custom_fonts() {
wp_enqueue_style( 'maxwell-custom-fonts', get_template_directory_uri() . '/assets/css/custom-fonts.css', array(), '20180413' );
}
add_action( 'wp_enqueue_scripts', 'maxwell_custom_fonts', 1 );
add_action( 'enqueue_block_editor_assets', 'maxwell_custom_fonts', 1 );
/**
* Enqueue editor styles for the new Gutenberg Editor.
*/
function maxwell_block_editor_assets() {
wp_enqueue_style( 'maxwell-editor-styles', get_theme_file_uri( '/assets/css/gutenberg-styles.css' ), array(), '20191118', 'all' );
}
add_action( 'enqueue_block_editor_assets', 'maxwell_block_editor_assets' );
/**
* Add custom sizes for featured images
*/
function maxwell_add_image_sizes() {
// Add Slider Image Size.
add_image_size( 'maxwell-slider-image', 850, 500, true );
// Add different thumbnail sizes for Magazine Posts widgets.
add_image_size( 'maxwell-thumbnail-small', 120, 80, true );
add_image_size( 'maxwell-thumbnail-medium', 360, 230, true );
add_image_size( 'maxwell-thumbnail-large', 600, 380, true );
}
add_action( 'after_setup_theme', 'maxwell_add_image_sizes' );
/**
* Make custom image sizes available in Gutenberg.
*/
function maxwell_add_image_size_names( $sizes ) {
return array_merge( $sizes, array(
'post-thumbnail' => esc_html__( 'Maxwell Single Post', 'maxwell' ),
'maxwell-thumbnail-large' => esc_html__( 'Maxwell Magazine Post', 'maxwell' ),
'maxwell-thumbnail-small' => esc_html__( 'Maxwell Thumbnail', 'maxwell' ),
) );
}
add_filter( 'image_size_names_choose', 'maxwell_add_image_size_names' );
/**
* Include Files
*/
// Include Theme Info page.
require get_template_directory() . '/inc/theme-info.php';
// Include Theme Customizer Options.
require get_template_directory() . '/inc/customizer/customizer.php';
require get_template_directory() . '/inc/customizer/default-options.php';
// Include SVG Icon Functions.
require get_template_directory() . '/inc/icons.php';
// Include Extra Functions.
require get_template_directory() . '/inc/extras.php';
// Include Template Functions.
require get_template_directory() . '/inc/template-tags.php';
// Include support functions for Theme Addons.
require get_template_directory() . '/inc/addons.php';
// Include Post Slider Setup.
require get_template_directory() . '/inc/slider.php';
// Include Magazine Functions.
require get_template_directory() . '/inc/magazine.php';
// Include Widget Files.
require get_template_directory() . '/inc/widgets/widget-magazine-posts-columns.php';
require get_template_directory() . '/inc/widgets/widget-magazine-posts-grid.php';