-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions.php
1155 lines (841 loc) · 33.8 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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*------------------------------------
* Theme: Air by studio.bio
* File: Main functions file
* Author: Joshua Michaels
* URI: https://studio.bio/themes/air
*------------------------------------
*
* We've moved all of the theme functions to this single
* file to keep things tidy.
*
* Extra development and debugging functions can be found
* in air.php. Uncomment the below require_once below.
*
*/
/* air development and debug functions
(not required but helper stuff for debugging and development)
*/
// require_once( 'library/air.php' );
/* WordPress Admin functions (for customizing the WP Admin)
(also not required so comment it out if you don't need it)
*/
require_once( 'library/admin.php' );
// WordPress Customizer functions and enqueues
require_once( 'library/customizer.php' );
/************************************
* Air Takeoff
*
* Now calling all seats/all rows.
*
* Wheels up!
*
************************************/
add_action( 'after_setup_theme', 'air_takeoff' );
function air_takeoff() {
// editor style
add_editor_style( get_stylesheet_directory_uri() . '/library/css/editor/editor-style.css' );
// let's get language support going, if you need it
load_theme_textdomain( 'airtheme', get_template_directory() . '/library/translation' );
// cleanup the <head>
add_action( 'init', 'air_head_cleanup' );
// remove WP version from RSS
add_filter( 'the_generator', 'air_rss_version' );
// remove pesky injected css for recent comments widget
add_filter( 'wp_head', 'air_remove_wp_widget_recent_comments_style', 1 );
// clean up comment styles in the head
add_action( 'wp_head', 'air_remove_recent_comments_style', 1 );
// clean up gallery output in wp
add_filter( 'gallery_style', 'air_gallery_style' );
// enqueue the styles and scripts
add_action( 'wp_enqueue_scripts', 'air_scripts_and_styles', 999 );
// support the theme stuffs
air_theme_support();
// adding sidebars to Wordpress
add_action( 'widgets_init', 'air_register_sidebars' );
// cleaning up <p> tags around images
add_filter( 'the_content', 'air_filter_ptags_on_images' );
// clean up the default WP excerpt
add_filter( 'excerpt_more', 'air_excerpt_more' );
// new body_open() function added in WP 5.2
// https://generatewp.com/wordpress-5-2-action-that-every-theme-should-use/
if ( ! function_exists( 'wp_body_open' ) ) {
/**
* Fire the wp_body_open action.
*
* Added for backwards compatibility to support WordPress versions prior to 5.2.0.
*/
function wp_body_open() {
/**
* Triggered after the opening <body> tag.
*/
do_action( 'wp_body_open' );
}
}
} /* end air takeoff */
/************* THUMBNAIL SIZE OPTIONS *************/
// Thumbnail sizes
add_image_size( 'air-image-600', 600, 600, true );
add_image_size( 'air-image-300', 300, 300, true );
add_image_size( 'air-image-150', 150, 150, true );
/*
to add more sizes, simply copy a line from above
and change the dimensions & name. As long as you
upload a "featured image" as large as the biggest
set width or height, all the other sizes will be
auto-cropped.
To call a different size, simply change the text
inside the thumbnail function.
For example, to call the 300 x 100 sized image,
we would use the function:
<?php the_post_thumbnail( 'air-image-300' ); ?>
for the 600 x 150 image:
<?php the_post_thumbnail( 'air-image-600' ); ?>
You can change the names and dimensions to whatever
you like. Enjoy!
*/
add_filter( 'image_size_names_choose', 'air_custom_image_sizes' );
function air_custom_image_sizes( $sizes ) {
return array_merge( $sizes, array(
'air-image-600' => __('600px by 600px', 'airtheme'),
'air-image-300' => __('300px by 300px', 'airtheme'),
'air-image-150' => __('150px by 150px', 'airtheme'),
)
);
}
/*
The function above adds the ability to use the dropdown menu to select
the new images sizes you have just created from within the media manager
when you add media to your content blocks. If you add more image sizes,
duplicate one of the lines in the array and name it according to your
new image size.
*/
/************* ACTIVE SIDEBARS ********************/
// Sidebars & Widgetized Areas
function air_register_sidebars() {
register_sidebar( array(
'id' => 'sidebar1',
'name' => __( 'Sidebar 1', 'airtheme' ),
'description' => __( 'The first (primary) sidebar.', 'airtheme' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
)
);
/*
to add more sidebars or widgetized areas, just copy
and edit the above sidebar code. In order to call
your new sidebar just use the following code:
Just change the name to whatever your new
sidebar's id is, for example:
register_sidebar( array(
'id' => 'sidebar2',
'name' => __( 'Sidebar 2', 'airtheme' ),
'description' => __( 'The second (secondary) sidebar.', 'airtheme' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
)
);
To call the sidebar in your template, you can just copy
the sidebar.php file and rename it to your sidebar's name.
So using the above example, it would be:
sidebar-sidebar2.php
*/
} // don't remove this bracket!
/*********************
COMMENTS
Blah blah blah.
*********************/
// Adding a custom gravatar. Customize this to add your own. Or delete it. It's totally up to you.
add_filter( 'avatar_defaults', 'new_default_avatar' );
function new_default_avatar( $avatar_defaults ) {
//Set the URL where the image file for your avatar is located
$new_avatar_url = get_stylesheet_directory_uri() . '/library/images/custom-gravatar.png';
// var_dump($new_avatar_url);
//Set the text that will appear to the right of your avatar in Settings>>Discussion
$avatar_defaults[$new_avatar_url] = 'Custom Avatar';
return $avatar_defaults;
}
// Comment Layout
function air_comments( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment; ?>
<div id="comment-<?php comment_ID(); ?>" <?php comment_class('comment-wrap'); ?>>
<article class="article-comment">
<header class="comment-author vcard">
<?php
/*
this is the new responsive optimized comment image. It used the new HTML5 data-attribute to display comment gravatars on larger screens only. What this means is that on larger posts, mobile sites don't have a ton of requests for comment images. This makes load time incredibly fast! If you'd like to change it back, just replace it with the regular wordpress gravatar call:
echo get_avatar($comment,$size='32',$default='<path_to_url>' );
*/
?>
<?php // custom gravatar call ?>
<?php
// create variable
$bgauthemail = get_comment_author_email();
?>
<img data-gravatar="//www.gravatar.com/avatar/<?php echo md5( $bgauthemail ); ?>?s=256" class="load-gravatar avatar avatar-48 photo" height="64" width="64" src="<?php echo get_template_directory_uri(); ?>/library/images/custom-gravatar.png" />
<?php // end custom gravatar call ?>
<div class="comment-meta">
<?php printf(__( '<cite class="fn">%1$s</cite> %2$s', 'airtheme' ), get_comment_author_link(), edit_comment_link(__( '(Edit)', 'airtheme' ),' ','') ) ?>
<time datetime="<?php echo comment_time('Y-m-j'); ?>">
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time(__( 'F jS, Y', 'airtheme' )); ?> </a>
</time>
</div>
</header>
<?php if ( $comment->comment_approved == '0' ) : ?>
<div class="alert alert-info">
<p><?php _e( 'Your comment is awaiting moderation.', 'airtheme' ) ?></p>
</div>
<?php endif; ?>
<section class="comment-content">
<?php comment_text() ?>
</section>
<div class="comment-reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</article>
<?php // </li> is added by WordPress automatically ?>
<?php } // don't remove this bracket!
/*
Use this to add Google or other web fonts.
*/
// add_action( 'wp_enqueue_scripts', 'air_fonts' );
// function air_fonts() {
// wp_enqueue_style( 'air-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400,600,400italic,' );
// }
/****************************************
* SCHEMA *
http://www.longren.io/add-schema-org-markup-to-any-wordpress-theme/
****************************************/
function html_schema() {
$schema = 'https://schema.org/';
// Is single post
if( is_single() ) {
$type = "Article";
}
// Is blog home, archive or category
else if( is_home() || is_archive() || is_category() ) {
$type = "Blog";
}
// Is static front page
else if( is_front_page() ) {
$type = "Website";
}
// Is a general page
else {
$type = 'WebPage';
}
echo 'itemscope="itemscope" itemtype="' . $schema . $type . '"';
}
/*********************************
WP_HEAD CLEANUP
The default WordPress head is a mess.
Let's clean it up by removing all
the junk we don't need.
**********************************/
function air_head_cleanup() {
// category feeds
remove_action( 'wp_head', 'feed_links_extra', 3 );
// post and comment feeds
remove_action( 'wp_head', 'feed_links', 2 );
// EditURI link
remove_action( 'wp_head', 'rsd_link' );
// windows live writer
remove_action( 'wp_head', 'wlwmanifest_link' );
// previous link
remove_action( 'wp_head', 'parent_post_rel_link' );
// start link
remove_action( 'wp_head', 'start_post_rel_link' );
// links for adjacent posts
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
// WP version
remove_action( 'wp_head', 'wp_generator' );
// remove WP version from css
add_filter( 'style_loader_src', 'air_remove_wp_ver_css_js', 9999 );
// remove WP version from scripts
add_filter( 'script_loader_src', 'air_remove_wp_ver_css_js', 9999 );
} /* end air head cleanup */
// remove WP version from RSS
function air_rss_version() {
return ''; // it's as if it is not even there
}
// remove WP version from scripts
function air_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
// remove injected CSS for recent comments widget
function air_remove_wp_widget_recent_comments_style() {
if ( has_filter( 'wp_head', 'wp_widget_recent_comments_style' ) ) {
remove_filter( 'wp_head', 'wp_widget_recent_comments_style' );
}
}
// remove injected CSS from recent comments widget
function air_remove_recent_comments_style() {
global $wp_widget_factory;
if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
remove_action( 'wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style') );
}
}
// remove injected CSS from gallery
function air_gallery_style($css) {
return preg_replace( "!<style type='text/css'>(.*?)</style>!s", '', $css );
}
/*********************
SCRIPTS & ENQUEUEING
*********************/
// loading modernizr and jquery, comment reply and custom scripts
function air_scripts_and_styles() {
global $wp_styles; // call global $wp_styles variable to add conditional wrapper around ie stylesheet the WordPress way
if ( !is_admin() ) {
/**
* Note: we have removed Modernizr but if you need it, go here and create your custom build:
* https://modernizr.com
*
* Then uncomment the enqueue below, replacing the filename with your modernizr script.
*/
// wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/library/js/libs/your-modernizr-build.js', array(), '3.6.0', false );
// register main stylesheet
wp_enqueue_style( 'air-stylesheet', get_template_directory_uri() . '/library/css/style.css', array(), '', 'all' );
// comment reply script for threaded comments
if ( is_singular() AND comments_open() AND ( get_option('thread_comments') == 1 )) { wp_enqueue_script( 'comment-reply' ); }
// adding scripts file in the footer
wp_enqueue_script( 'air-js', get_template_directory_uri() . '/library/js/scripts.js', array( 'jquery' ), '', true );
// accessibility (a11y) scripts
wp_enqueue_script( 'air-a11y', get_template_directory_uri() . '/library/js/a11y.js', array( 'jquery' ), '', true );
// air extra scripts. Uncomment to use. Or better yet, copy what you need to the main scripts folder or on the page(s) you need it
// wp_enqueue_script( 'air-extra-js', get_template_directory_uri() . '/library/js/extras/extra-scripts.js', array( 'jquery' ), '', true );
}
}
/*********************
GUTENBERG ENQUEUES
These are kept out of the main enqueue
function in case you don't need them.
*********************/
/**
*
* Gutenberg Editor Styles
*
* Enqueue block editor style for Gutenberg
* This applies to the admin editor *only*,
* (e.g. not on the front end);
*
*/
add_action( 'enqueue_block_editor_assets', 'air_block_editor_styles' );
function air_block_editor_styles() {
wp_enqueue_style( 'air-block-editor-styles', get_template_directory_uri( '/library/css/editor/block-editor.css' ), false, '1.0', 'all' );
}
/**
* Gutenberg Front End Styles
*
* Enqueue front end styles for Gutenberg.
*
*/
add_action( 'enqueue_block_assets', 'air_gutenberg_styles' );
function air_gutenberg_styles() {
wp_enqueue_style( 'air-gutenberg-styles', get_template_directory_uri( '/library/css/editor/gutenberg.css' ), false, '1.0', 'all' );
}
/****************************************
* REMOVE WP EXTRAS & DEQUEUEING STUFFS *
****************************************/
/*
* Remove emojis: because WordPress is serious business.
* But, if you want emojis, don't let me stop you from having a good time.
* To enable emojis, comment these functions out or just delete them.
*/
add_action( 'init', 'disable_wp_emojicons' );
function disable_wp_emojicons() {
// all actions related to emojis
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
// filter to remove TinyMCE emojis
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
function disable_emojicons_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
/*
* Dequeue jQuery Migrate
* I'm commenting this out by default. Why? Because Gravity Forms *requires* it
* for some form functions to work...***eye roll***.
*/
// add_action( 'wp_default_scripts', 'air_dequeue_jquery_migrate' );
// function air_dequeue_jquery_migrate( $scripts ) {
// if (! empty( $scripts->registered['jquery'] ) ) {
// $jquery_dependencies = $scripts->registered['jquery']->deps;
// $scripts->registered['jquery']->deps = array_diff( $jquery_dependencies, array( 'jquery-migrate' ) );
// }
// }
// Remove wp-embed.min.js from the front end. Commented out by default as you may need it.
// See here: https://wordpress.stackexchange.com/questions/211701/what-does-wp-embed-min-js-do-in-wordpress-4-4
// add_action( 'init', function() {
// // Remove the REST API endpoint.
// remove_action('rest_api_init', 'wp_oembed_register_route');
// // Turn off oEmbed auto discovery.
// // Don't filter oEmbed results.
// remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
// // Remove oEmbed discovery links.
// remove_action('wp_head', 'wp_oembed_add_discovery_links');
// // Remove oEmbed-specific JavaScript from the front-end and back-end.
// remove_action('wp_head', 'wp_oembed_add_host_js');
// }, PHP_INT_MAX - 1 );
// Remove the p from around imgs (http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/)
// This only works for the main content box, not using ACF or other page builders.
// Added small bit of javascript in scripts.js that will work everywhere.
// Keeping this in in case people are still using it.
add_filter('the_content', 'air_filter_ptags_on_images');
function air_filter_ptags_on_images( $content ) {
return preg_replace('/<pp>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
// Simple function to remove the [...] from excerpt and add a 'Read More »' link.
function air_excerpt_more($more) {
global $post;
// edit here if you like
return '... <a class="excerpt-read-more" href="'. get_permalink( $post->ID ) . '" title="'. __( 'Read ', 'airtheme' ) . esc_attr( get_the_title( $post->ID ) ).'">'. __( 'Read more »', 'airtheme' ) .'</a>';
}
/*********************
THEME SUPPORT
*********************/
// support all of the theme things
function air_theme_support() {
// wp thumbnails (see sizes above)
add_theme_support( 'post-thumbnails' );
// default thumb size
set_post_thumbnail_size(125, 125, true);
// wp custom background (thx to @bransonwerner for update)
add_theme_support( 'custom-background', array(
'default-image' => '', // background image default
'default-color' => '', // background color default (don't add the #)
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => '',
)
);
// Custom Header Image
add_theme_support( 'custom-header', array(
'default-image' => get_template_directory_uri() . '/library/images/header-image.png',
'default-text-color' => '000',
'width' => 1440,
'height' => 220,
'flex-width' => true,
'flex-height' => true,
'header-text' => true,
'uploads' => true,
'wp-head-callback' => 'air_style_header',
)
);
// Custom Logo
add_theme_support( 'custom-logo', array(
'height' => 100,
'width' => 100,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
)
);
// rss thingy
add_theme_support( 'automatic-feed-links' );
// To add another menu, uncomment the second line and change it to whatever you want. You can have even more menus.
register_nav_menus( array(
'main-nav' => __( 'The Main Menu', 'airtheme' ), // main nav in header
// 'footer-links' => __( 'Footer Links', 'airtheme' ) // secondary nav in footer. Uncomment to use or edit.
)
);
// Title tag. Note: this still isn't working with Yoast SEO
add_theme_support( 'title-tag' );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Enable support for HTML5 markup.
add_theme_support( 'html5', array(
'comment-list',
'comment-form',
'search-form',
'gallery',
'caption'
)
);
/*
* POST FORMATS
* Ahhhh yes, the wild and wonderful world of Post Formats.
* I've never really gotten into them but I could see some
* situations where they would come in handy. Here's a few
* examples: https://www.competethemes.com/blog/wordpress-post-format-examples/
*
* This theme doesn't use post formats per se but we need this
* to pass the theme check.
*
* We may add better support for post formats in the future.
*
* If you want to use them in your project, do so by all means.
* We won't judge you. Ok, maybe a little bit.
*
*/
add_theme_support( 'post-formats', array(
'aside', // title less blurb
'gallery', // gallery of images
'link', // quick link to other site
'image', // an image
'quote', // a quick quote
'status', // a Facebook like status update
'video', // video
'audio', // audio
'chat' // chat transcript
)
);
// Gutenberg support: https://www.billerickson.net/getting-your-theme-ready-for-gutenberg/
// https://wordpress.org/gutenberg/handbook/extensibility/theme-support/
// .alignwide styles added to _768up
add_theme_support( 'align-wide' );
add_theme_support( 'editor-color-palette',
array(
'name' => 'studio bio blue',
'color' => '#0056ac',
),
array(
'name' => 'studio bio light blue',
'color' => '#99bbde',
),
array(
'name' => 'studio bio midnight',
'color' => '#001c3a',
),
array(
'name' => 'studio bio purple',
'color' => '#cc0099',
),
array(
'name' => 'studio bio red',
'color' => '#f23e2f',
),
array(
'name' => 'grey 70',
'color' => '#444444',
),
array(
'name' => 'grey 20',
'color' => '#cccccc',
)
);
// Adds responsive embeds to Gutenberg blocks
add_theme_support( 'responsive-embeds' );
// Adds default Gutenberg styles to custom blocks
// Delete/comment out if you are adding your own block styles
add_theme_support( 'wp-block-styles' );
// To limit the Gutenberg editor to your theme colors, uncomment this
// add_theme_support( 'disable-custom-colors' );
} /* end air theme support */
/**
* $content_width.
*
* We need this to pass the theme check. Massive eye roll.
* IT DOESN'T MAKE SENSE WITH RESPONSIVE LAYOUTS.
* I'm looking at you, WordPress Trac peoples.
*
* Probably best to not touch this unless you really want to
* assign a maximum content width.
*
* https://codex.wordpress.org/Content_Width
*
*/
// commented by default now as it breaks Instagram Gutenberg Block embeds.
if ( ! isset( $content_width ) ) {
// $content_width = '100%';
}
/*
* WooCommerce Support
*
* This function only removes the warning in the WP admin when
* WooCommerce is installed. To fully support WooCommerce you
* will need to add some stuff to your product loops.
*
* See here: https://docs.woocommerce.com/document/third-party-custom-theme-compatibility/
*
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
}
/*********************
RELATED POSTS FUNCTION
*********************/
/**
* air Related Posts.
*
* Adapted from this gist:
* https://gist.github.com/claudiosanches/3167825
*
* Replaced old related posts function from Bones.
* Added: 2018-05-03
*
* Usage:
* To show related by categories:
* Add in single.php <?php air_related_posts(); ?>.
* To show related by tags:
* Add in single.php <?php air_related_posts('tag'); ?>.
*
* @global array $post
* WP global post.
* @param string $display
* Set category or tag.
* @param int $qty
* Number of posts to be displayed.
* @param bool $images
* Enable or disable displaying images.
* @param string $title
* Set the widget title.
*/
function air_related_posts( $display = 'category', $qty = 5, $images = true, $title = 'Related Posts' ) {
global $post;
$show = false;
$post_qty = (int) $qty;
switch ( $display ) :
case 'tag':
$tags = wp_get_post_tags( $post->ID) ;
if ( $tags ) {
$show = true;
$tag_ids = array();
foreach ( $tags as $individual_tag ) {
$tag_ids[] = $individual_tag->term_id;
}
$args = array(
'tag__in' => $tag_ids,
'post__not_in' => array( $post->ID ),
'posts_per_page' => $post_qty,
'ignore_sticky_posts' => 1
);
}
break;
default :
$categories = get_the_category( $post->ID );
if ( $categories ) {
$show = true;
$category_ids = array();
foreach ( $categories as $individual_category ) {
$category_ids[] = $individual_category->term_id;
}
$args = array(
'category__in' => $category_ids,
'post__not_in' => array( $post->ID ),
'showposts' => $post_qty,
'ignore_sticky_posts' => 1
);
}
endswitch;
if ( $show == true ) {
$related = new wp_query( $args );
if ( $related->have_posts() ) {
$layout = '<div class="related-posts">';
$layout .= '<h3>' . strip_tags( $title ) . '</h3>';
$layout .= '<ul class="nostyle related-posts-list">';
while ( $related->have_posts() ) {
$related->the_post();
$layout .= '<li class="related-post">';
if ( $images == true ) {
$layout .= '<span class="related-thumb">';
$layout .= '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_post_thumbnail() . '</a>';
$layout .= '</span>';
}
$layout .= '<span class="related-title">';
$layout .= '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a>';
$layout .= '</span>';
$layout .= '</li>';
}
$layout .= '</ul>';
$layout .= '</div>';
echo $layout;
}
wp_reset_query();
}
}
/*********************
PAGE NAVI
*********************/
/**
* Numeric Page Navi (built into the theme by default).
* (Updated 2018-05-17)
*
* If you're using this with a custom WP_Query, make sure
* to add your query variable as an argument and this
* function will play nice. Example:
*
* air_page_navi( $query );
*
* Also make sure your query has pagination set, e.g.:
* $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
* (or something similar)
* See the codex: https://codex.wordpress.org/Pagination
*
* @param array $wp_query
*
*/
function air_page_navi( $wp_query ) {
$pages = $wp_query->max_num_pages;
$big = 999999999; // need an unlikely integer
if ( $pages > 1 ) {
$page_current = max(1, get_query_var('paged'));
echo '<nav class="pagination">';
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => $page_current,
'total' => $pages,
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3
));
echo '</nav>';
}
}
/*
****************************************
* air SPECIAL FUNCTIONS *
****************************************
*/
// Body Class functions
// Adds more slugs to body class so we can style individual pages + posts.
add_filter( 'body_class', 'air_body_class' );
function air_body_class( $classes ) {
// Adds new classes for blogroll page (list of blog posts)
// good for containing full-width images from Gutenberg
// Added: 2018-12-07
global $wp_query;
if ( isset( $wp_query ) && (bool) $wp_query->is_posts_page ) {
$classes[] = 'blogroll page-blog';
}
global $post;
if ( isset( $post ) ) {
/* Un comment below if you want the post_type-post_name body class */
/* $classes[] = $post->post_type . '-' . $post->post_name; */
$pagetemplate = get_post_meta( $post->ID, '_wp_page_template', true);
$classes[] = sanitize_html_class( str_replace( '.', '-', $pagetemplate ), '' );
$classes[] = $post->post_name;
}
if (is_page()) {
global $post;
if ( $post->post_parent ) {
// Parent post name/slug
$parent = get_post( $post->post_parent );
$classes[] = $parent->post_name;