-
Notifications
You must be signed in to change notification settings - Fork 9
/
functions.php
482 lines (420 loc) · 14.4 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<?php
/**
* SiteOrigin North functions and definitions.
*
* @license GPL 2.0
*/
define( 'SITEORIGIN_THEME_VERSION', 'dev' );
define( 'SITEORIGIN_THEME_JS_PREFIX', '' );
define( 'SITEORIGIN_THEME_CSS_PREFIX', '' );
// The settings manager.
include get_template_directory() . '/inc/settings/settings.php';
if ( ! function_exists( 'siteorigin_north_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 siteorigin_north_setup() {
load_theme_textdomain( 'siteorigin-north', 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.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for the custom logo.
*/
add_theme_support( 'custom-logo' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 650, 650 );
add_image_size( 'north-thumbnail-no-sidebar', 1040, 650, true );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'siteorigin-north' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
* See http://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'siteorigin_north_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
) ) );
// Allowing use of shortcodes in taxonomy descriptions
add_filter( 'term_description', 'shortcode_unautop' );
add_filter( 'term_description', 'do_shortcode' );
// Add support for WooCommerce.
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-slider' );
if ( ! defined( 'SITEORIGIN_PANELS_VERSION' ) ) {
// Only include panels lite if the panels plugin doesn't exist.
include get_template_directory() . '/inc/panels-lite/panels-lite.php';
}
add_theme_support( 'siteorigin-panels', array(
'home-page' => true,
'responsive' => ! siteorigin_setting( 'responsive_disabled' ),
) );
// We'll use archive settings
add_theme_support( 'siteorigin-template-settings' );
}
} // siteorigin_north_setup
add_action( 'after_setup_theme', 'siteorigin_north_setup' );
if ( ! function_exists( 'siteorigin_north_premium_setup' ) ) {
/**
* Add support for premium theme components
*/
function siteorigin_north_premium_setup() {
// This theme supports the no attribution addon
add_theme_support( 'siteorigin-premium-no-attribution', array(
'filter' => 'siteorigin_north_footer_credits',
'enabled' => siteorigin_setting( 'branding_attribution' ),
'siteorigin_setting' => 'branding_attribution',
) );
// This theme supports the no attribution addon
add_theme_support( 'siteorigin-premium-ajax-comments', array(
'enabled' => siteorigin_setting( 'blog_ajax_comments' ),
'siteorigin_setting' => 'blog_ajax_comments',
) );
}
// Logo Booster.
add_theme_support( 'siteorigin-premium-logo-booster' );
}
add_action( 'after_setup_theme', 'siteorigin_north_premium_setup' );
if ( ! function_exists( 'siteorigin_north_content_width' ) ) {
/**
* 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 siteorigin_north_content_width() {
global $content_width;
$content_width = apply_filters( 'siteorigin_north_content_width', 650 );
}
}
add_action( 'after_setup_theme', 'siteorigin_north_content_width', 0 );
if ( ! function_exists( 'siteorigin_north_post_class_filter' ) ) {
/**
* Filter post classes as required.
*
* @see https://codex.wordpress.org/Function_Reference/post_class.
*/
function siteorigin_north_post_class_filter( $classes ) {
$classes[] = 'post';
// Resolves structured data issue in core. See https://core.trac.wordpress.org/ticket/28482.
if ( is_page() ) {
$class_key = array_search( 'hentry', $classes );
if ( $class_key !== false ) {
unset( $classes[ $class_key ] );
}
}
$classes = array_unique( $classes );
return $classes;
}
}
add_filter( 'post_class', 'siteorigin_north_post_class_filter' );
if ( ! function_exists( 'siteorigin_north_disable_responsive' ) ) {
/**
* Disable responsive layout.
*/
function siteorigin_north_disable_responsive() {
if ( siteorigin_setting( 'responsive_disabled' ) == false ) {
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
}
}
}
add_action( 'wp_head', 'siteorigin_north_disable_responsive', 0 );
if ( ! function_exists( 'siteorigin_north_widgets_init' ) ) {
/**
* Register widget area.
*
* @see http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function siteorigin_north_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Main Sidebar', 'siteorigin-north' ),
'id' => 'main-sidebar',
'description' => esc_html__( 'Visible on posts and pages that use the default layout.', 'siteorigin-north' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets', 'siteorigin-north' ),
'id' => 'footer-sidebar',
'description' => esc_html__( 'A column will be automatically assigned to each widget inserted.', 'siteorigin-north' ),
'before_widget' => '<div class="widget-wrapper"><aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside></div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Top Bar', 'siteorigin-north' ),
'id' => 'topbar-sidebar',
'description' => esc_html__( 'Replaces the top bar text.', 'siteorigin-north' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
if ( function_exists( 'is_woocommerce' ) ) {
register_sidebar( array(
'name' => esc_html__( 'Shop Sidebar', 'siteorigin-north' ),
'id' => 'sidebar-shop',
'description' => esc_html__( 'Displays on WooCommerce pages.', 'siteorigin-north' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
}
}
add_action( 'widgets_init', 'siteorigin_north_widgets_init' );
if ( ! function_exists( 'siteorigin_north_scripts' ) ) {
/**
* Enqueue scripts and styles.
*/
function siteorigin_north_scripts() {
// Theme stylesheet.
wp_enqueue_style(
'siteorigin-north-style',
get_template_directory_uri() . '/style' . SITEORIGIN_THEME_CSS_PREFIX . '.css',
array(),
SITEORIGIN_THEME_VERSION
);
// Theme icons.
wp_enqueue_style(
'siteorigin-north-icons', get_template_directory_uri() . '/css/north-icons' . SITEORIGIN_THEME_CSS_PREFIX . '.css',
array(),
SITEORIGIN_THEME_VERSION
);
// Flexslider
wp_enqueue_style(
'siteorigin-north-flexslider',
get_template_directory_uri() . '/css/flexslider' . SITEORIGIN_THEME_CSS_PREFIX . '.css'
);
wp_enqueue_script(
'jquery-flexslider',
get_template_directory_uri() . '/js/jquery.flexslider' . SITEORIGIN_THEME_JS_PREFIX . '.js',
array( 'jquery' ),
'2.6.3',
true
);
// jQuery Transit.
wp_enqueue_script(
'jquery-transit',
get_template_directory_uri() . '/js/jquery.transit' . SITEORIGIN_THEME_JS_PREFIX . '.js',
array( 'jquery' ),
'0.9.12',
true
);
// jQuery FitVids.
if ( siteorigin_setting( 'responsive_fitvids' ) ) {
wp_enqueue_script(
'jquery-fitvids',
get_template_directory_uri() . '/js/jquery.fitvids' . SITEORIGIN_THEME_JS_PREFIX . '.js',
array( 'jquery' ),
'1.1',
true
);
}
// Theme JavaScript.
wp_enqueue_script(
'siteorigin-north-script',
get_template_directory_uri() . '/js/north' . SITEORIGIN_THEME_JS_PREFIX . '.js',
array( 'jquery' ),
SITEORIGIN_THEME_VERSION,
true
);
// Skip link focus fix.
wp_enqueue_script(
'siteorigin-north-skip-link',
get_template_directory_uri() . '/js/skip-link-focus-fix' . SITEORIGIN_THEME_JS_PREFIX . '.js',
array(),
SITEORIGIN_THEME_VERSION,
true
);
// Add settings variables used by main theme JS.
$logo_sticky_scale = apply_filters( 'siteorigin_north_logo_sticky_scale', 0.755 );
$sticky_topbar = apply_filters( 'siteorigin_north_sticky_topbar', false );
wp_localize_script(
'siteorigin-north-script',
'siteoriginNorth',
array(
'smoothScroll' => siteorigin_setting( 'navigation_smooth_scroll' ),
'logoScale' => is_numeric( $logo_sticky_scale ) ? $logo_sticky_scale : 0.755,
'collapse' => siteorigin_setting( 'responsive_menu_breakpoint' ),
'fitvids' => siteorigin_setting( 'responsive_fitvids' ),
'stickyTopbar' => $sticky_topbar,
)
);
// Comment reply.
if (
is_singular() &&
comments_open() &&
get_option( 'thread_comments' )
) {
wp_enqueue_script( 'comment-reply' );
}
}
}
add_action( 'wp_enqueue_scripts', 'siteorigin_north_scripts' );
/**
* Enqueue Block Editor styles.
*/
function siteorigin_north_block_editor_styles() {
wp_enqueue_style( 'siteorigin-north-block-editor-styles', get_template_directory_uri() . '/style-editor.css', SITEORIGIN_THEME_VERSION );
}
add_action( 'enqueue_block_editor_assets', 'siteorigin_north_block_editor_styles' );
if ( ! function_exists( 'siteorigin_north_siteorigin_premium' ) ) {
function siteorigin_north_siteorigin_premium( $themes ) {
$themes[] = 'siteorigin-north';
return $themes;
}
}
add_filter( 'siteorigin_premium_themes', 'siteorigin_north_siteorigin_premium' );
if ( ! function_exists( 'siteorigin_north_filter_comment_form_default_fields' ) ) {
/**
* Modify comments form - change placeholders.
*/
function siteorigin_north_filter_comment_form_default_fields( $fields ) {
$placeholders = apply_filters(
'siteorigin_north_comment_form_placeholders',
array(
'author' => esc_html__( 'Enter Your Name', 'siteorigin-north' ),
'email' => esc_html__( 'Enter Your Email', 'siteorigin-north' ),
'url' => esc_html__( 'Your Site URL', 'siteorigin-north' ),
)
);
$default_author = array( '<label for="author"', '<input id="author" ' );
$default_email = array( '<label for="email"', '<input id="email" ' );
$default_url = array( '<label for="url"', '<input id="url" ' );
$replace_author = array(
'<label for="author" class="screen-reader-text"',
'<input id="author" placeholder="' . esc_attr( $placeholders['author'] ) . '" ',
);
$replace_email = array(
'<label for="email" class="screen-reader-text"',
'<input id="email" placeholder="' . esc_attr( $placeholders['email'] ) . '" ',
);
$replace_url = array(
'<label for="url" class="screen-reader-text"',
'<input id="url" placeholder="' . esc_attr( $placeholders['url'] ) . '" ',
);
if ( isset( $fields['author'] ) ) {
$fields['author'] = str_replace(
$default_author,
$replace_author,
$fields['author']
);
}
if ( isset( $fields['email'] ) ) {
$fields['email'] = str_replace(
$default_email,
$replace_email,
$fields['email']
);
}
if ( isset( $fields['url'] ) ) {
$fields['url'] = str_replace(
$default_url,
$replace_url,
$fields['url']
);
}
return $fields;
}
}
add_filter( 'comment_form_default_fields', 'siteorigin_north_filter_comment_form_default_fields' );
if ( ! function_exists( 'siteorigin_north_filter_comment_form_defaults' ) ) {
/**
* Modify comments form - make labels screen-reader-text
*/
function siteorigin_north_filter_comment_form_defaults( $defaults ) {
$comment_placeholder = __( 'Enter your message', 'siteorigin-north' );
$default_comment = array(
'<label for="comment"',
'<textarea id="comment" '
);
$replace_comment = array(
'<label for="comment" class="screen-reader-text"',
'<textarea id="comment" placeholder="' . esc_attr( $comment_placeholder ) . '" ',
);
if ( ! empty( $defaults['comment_field'] ) ) {
$defaults['comment_field'] = str_replace(
$default_comment,
$replace_comment,
$defaults['comment_field']
);
$defaults['comment_field'] = '<div class="clear"></div>' . $defaults['comment_field'];
}
return $defaults;
}
}
add_filter( 'comment_form_defaults', 'siteorigin_north_filter_comment_form_defaults' );
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/*
* Load Jetpack compatibility file.
*/
if ( class_exists( 'Jetpack' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
/**
* Load the theme settings file
*/
require get_template_directory() . '/inc/settings.php';
/**
* Support for SiteOrigin Page Builder
*/
require get_template_directory() . '/inc/siteorigin-panels.php';
/*
* Load support for WooCommerce.
*/
if ( function_exists( 'is_woocommerce' ) ) {
require get_template_directory() . '/woocommerce/functions.php';
}
/* IMPORTANT NOTICE: Please don't edit this file; any changes made here will be lost during the theme update process.
If you need to add custom functions, use the Code Snippets plugin (https://wordpress.org/plugins/code-snippets/) or a child theme. */