-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·2371 lines (2159 loc) · 109 KB
/
functions.php
File metadata and controls
executable file
·2371 lines (2159 loc) · 109 KB
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 // m20T1 functions and settings for WordPress
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
// Visual error reporting
error_reporting(0);
/////////////////////////////
// Initial Settings
/////////////////////////////
// Inline separator that appears in the post/page metadata
define( 'POST_SEPARATOR', '–' );
// Inline separator for the header breadcrumb trail
define( 'BREADCRUMB_SEPARATOR', '/' );
// Default: Read more excerpt at the text ending
define( 'MORE_TEXT', '[...]' );
// Default: SEO text excerpt length default
define( 'SEO_TEXT_LENGTH', 170 ); // Number of characters
// Default: Maximum excerpt length default
define( 'EXCERPT_LENGTH', 90 ); // Number of words
// Default: Shorten length of the content for the blog posts listings
define( 'SHORT_TEXT_LENGTH', 60 ); // Number of words
// Set the additional post types with a new line for each type
define( 'ADDITIONAL_POST_TYPE', [
/* [ 'Title (singular)', Title (plural)', 'dashicons-portfolio (https://developer.wordpress.org/resource/dashicons/)', 'Subtitle' ], */
[ 'Portfolio', 'Portfolios', 'dashicons-portfolio', 'The work I have done professionally' ],
// Note: Rename or create 'archive-portfolio.php' and 'single-portfolio.php' if changing the default post type slug
]);
// Register custom block styles for the Editor that correlate to block variations in theme.json
// https://developer.wordpress.org/news/2024/06/21/styling-sections-nested-elements-and-more-with-block-style-variations-in-wordpress-6-6/
add_action( 'init', function(){
// Separator: Dots Wide
register_block_style( 'core/separator', [
'name' => 'hr-dots',
'label' => __( 'Dots Wide', 'm20t1' ),
//'is_default' => true,
//'style_handle' => 'hr-double',
//'inline_style' => '.is-style-name {}'
]);
// Separator: Double Lines
register_block_style( 'core/separator', [
'name' => 'hr-double',
'label' => __( 'Double Line', 'm20t1' )
]);
// Separator: Skinny Line
register_block_style( 'core/separator', [
'name' => 'hr-skinny',
'label' => __( 'Skinny', 'm20t1' )
]);
// Separator: Gradient Fade
register_block_style( 'core/separator', [
'name' => 'hr-gradient',
'label' => __( 'Gradient Fade', 'm20t1' )
]);
// Separator: Angled Stripes
register_block_style( 'core/separator', [
'name' => 'hr-stripes',
'label' => __( 'Stripes', 'm20t1' )
]);
// Separator: Line/Pencil
register_block_style( 'core/separator', [
'name' => 'hr-pencil',
'label' => __( 'Pencil Line', 'm20t1' )
]);
// Separator: Hashmarks
register_block_style( 'core/separator', [
'name' => 'hr-hash',
'label' => __( 'Hashmarks', 'm20t1' )
]);
// Separator: Tiny Dots
register_block_style( 'core/separator', [
'name' => 'hr-tinydots',
'label' => __( 'Tiny Dots', 'm20t1' )
]);
// Separator: Jagged
register_block_style( 'core/separator', [
'name' => 'hr-jagged',
'label' => __( 'Jagged', 'm20t1' )
]);
// Separator: Heavy
register_block_style( 'core/separator', [
'name' => 'hr-heavy',
'label' => __( 'Heavy', 'm20t1' )
]);
// Table: Theme
register_block_style( 'core/table', [
'name' => 'table-theme',
'label' => __( 'Theme', 'm20t1' )
]);
// List: Color Bullets
register_block_style( 'core/list', [
'name' => 'list-color',
'label' => __( 'Color Bullets', 'm20t1' )
]);
// List: Squares
register_block_style( 'core/list', [
'name' => 'list-square',
'label' => __( 'Squares', 'm20t1' )
]);
// List: Triangles
register_block_style( 'core/list', [
'name' => 'list-triangle',
'label' => __( 'Triangles', 'm20t1' )
]);
// List: Arrows
register_block_style( 'core/list', [
'name' => 'list-arrows',
'label' => __( 'Arrows', 'm20t1' )
]);
// List: Double Arrows
register_block_style( 'core/list', [
'name' => 'list-dbl-arrows',
'label' => __( 'Dbl. Arrows', 'm20t1' )
]);
// List: Checkmarks
register_block_style( 'core/list', [
'name' => 'list-checkmarks',
'label' => __( 'Checkmarks', 'm20t1' )
]);
// List: Checks
register_block_style( 'core/list', [
'name' => 'list-checks',
'label' => __( 'Boxed Checks', 'm20t1' )
]);
// List: Dashes
register_block_style( 'core/list', [
'name' => 'list-dash',
'label' => __( 'Dashes', 'm20t1' )
]);
// List: Ornate number
register_block_style( 'core/list', [
'name' => 'list-ornate',
'label' => __( 'Ornate Num', 'm20t1' )
]);
// List: No bullets/numbers
register_block_style( 'core/list', [
'name' => 'list-plain',
'label' => __( 'No Bullets', 'm20t1' )
]);
// Paragraph: Justify text
register_block_style( 'core/paragraph', [
'name' => 'text-justify',
'label' => __( 'Justify', 'm20t1' )
]);
// Paragraph: Light text shadow
register_block_style( 'core/paragraph', [
'name' => 'text-shadow-soft',
'label' => __( 'Soft Shadow', 'm20t1' )
]);
// Paragraph: Hard text shadow
register_block_style( 'core/paragraph', [
'name' => 'text-shadow-hard',
'label' => __( 'Hard Shadow', 'm20t1' )
]);
// Paragraph: Purple glow shadow
register_block_style( 'core/paragraph', [
'name' => 'text-shadow-glow',
'label' => __( 'Purple Glow', 'm20t1' )
]);
// Paragraph: Subtitle
register_block_style( 'core/paragraph', [
'name' => 'text-subtitle',
'label' => __( 'Subtitle', 'm20t1' )
]);
// Paragraph: Outline text
register_block_style( 'core/paragraph', [
'name' => 'text-outline',
'label' => __( 'Outline', 'm20t1' )
]);
// Heading: Soft text shadow
register_block_style( 'core/heading', [
'name' => 'header-shadow-soft',
'label' => __( 'Soft Shadow', 'm20t1' )
]);
// Heading: Hard text shadow
register_block_style( 'core/heading', [
'name' => 'header-shadow-hard',
'label' => __( 'Hard Shadow', 'm20t1' )
]);
// Heading: 3D shadow
register_block_style( 'core/heading', [
'name' => 'header-shadow-3d',
'label' => __( '3D Shadow', 'm20t1' )
]);
// Heading: Embelishment
register_block_style( 'core/heading', [
'name' => 'header-embelish',
'label' => __( 'Embelishment', 'm20t1' )
]);
// Heading: Brushstroke
register_block_style( 'core/heading', [
'name' => 'header-brush',
'label' => __( 'Brushstroke', 'm20t1' )
]);
// Heading: Black Outline
register_block_style( 'core/heading', [
'name' => 'header-outline',
'label' => __( 'Black Outline', 'm20t1' )
]);
// Heading: Stripes
register_block_style( 'core/heading', [
'name' => 'header-stripes',
'label' => __( 'Stripes', 'm20t1' ),
'inline_style' => '.is-style-header-stripes::after,.is-style-header-stripes::before{background-image:url("data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 18 33\"><path d=\"M8 0h10L9 33H0Z\" fill=\"%2366666655\"/></svg>");height:1em;margin:0 6px}'
]);
// Heading: Text Shadow Color Offset
register_block_style( 'core/heading', [
'name' => 'header-coloroffset',
'label' => __( 'Color Offset', 'm20t1' )
]);
// Heading: Text Fill
register_block_style( 'core/heading', [
'name' => 'header-text-fill',
'label' => __( 'Text-Fill', 'm20t1' )
]);
// Quote: Basic style
register_block_style( 'core/quote', [
'name' => 'plain',
'label' => __( 'Plain', 'm20t1' )
]);
// Quote: Fancy style
register_block_style( 'core/quote', [
'name' => 'fancy',
'label' => __( 'Fancy', 'm20t1' )
]);
// PullQuote: Embelishment style
register_block_style( 'core/pullquote', [
'name' => 'pquote-embelish',
'label' => __( 'Embelishment', 'm20t1' )
]);
// Code: Terminal style from css-trick.com
register_block_style( 'core/code', [
'name' => 'code-terminal',
'label' => __( 'Terminal', 'm20t1' ),
'inline_style' => '@keyframes m20Ter{0%{background-color:#000}100%{background-color:#444}}'
]);
// Code: DOS style
register_block_style( 'core/code', [
'name' => 'code-msdos',
'label' => __( 'MS-DOS', 'm20t1' )
]);
// Code: MacOS style
register_block_style( 'core/code', [
'name' => 'code-macos',
'label' => __( 'MacOS', 'm20t1' )
]);
// Embed: Youtube Frame style
register_block_style( 'core/embed', [
'name' => 'embed-youtube',
'label' => __( 'Frame', 'm20t1' )
]);
// Embed: Youtube Thumbnail style
register_block_style( 'core/embed', [
'name' => 'embed-thumbnail',
'label' => __( 'Thumbnail', 'm20t1' )
]);
// Video: Shadow style
register_block_style( 'core/video', [
'name' => 'video-shadow',
'label' => __( 'Shadow', 'm20t1' )
]);
// Video: Glow style
register_block_style( 'core/video', [
'name' => 'video-glow',
'label' => __( 'White Glow', 'm20t1' )
]);
// Button: 3D Raised Style
register_block_style( 'core/button', [
'name' => 'button-3d',
'label' => __( 'Raised', 'm20t1' ),
]);
// Button: w/ Arrow Style
register_block_style( 'core/button', [
'name' => 'button-arrow',
'label' => __( 'w/ Arrow', 'm20t1' )
]);
// Button: Hard Shadow Style
register_block_style( 'core/button', [
'name' => 'button-border',
'label' => __( 'Hard Border', 'm20t1' )
]);
// Button: Glass Style
register_block_style( 'core/button', [
'name' => 'button-glass',
'label' => __( 'Glass', 'm20t1' )
]);
// Accordion: Right Arrow style
register_block_style( 'core/accordion-item', [
'name' => 'accordion-arrow',
'label' => __( 'Arrow', 'm20t1' )
]);
// Details: Left Cross style
register_block_style( 'core/details', [
'name' => 'details-cross',
'label' => __( 'Cross', 'm20t1' ),
'inline_style' => '.dark-mode .is-style-details-cross summary::before{filter:invert()} .is-style-details-cross summary::-webkit-details-marker, .is-style-details-cross summary::marker {display:none;content:""}'
]);
// Details: Right Arrow style
register_block_style( 'core/details', [
'name' => 'details-arrow',
'label' => __( 'Arrow', 'm20t1' ),
'inline_style' => '.dark-mode .is-style-details-arrow summary::after{filter:invert()} .is-style-details-arrow summary::-webkit-details-marker, .is-style-details-arrow summary::marker {display:none;content:""}'
]);
// Image: Fancy style
register_block_style( 'core/image', [
'name' => 'img-fancy',
'label' => __( 'Framed', 'm20t1' )
]);
// Image: Hand-Drawn
register_block_style( 'core/image', [
'name' => 'img-hand-drawn',
'label' => __( 'Hand Drawn', 'm20t1' )
]);
// Image: Old photo style
register_block_style( 'core/image', [
'name' => 'img-polaroid',
'label' => __( 'Polaroid', 'm20t1' )
]);
// Image: Filter Alpha Shadow Style
register_block_style( 'core/image', [
'name' => 'img-filter-shadow',
'label' => __( 'Alpha Shadow', 'm20t1' )
]);
// Image: Book landscape
register_block_style( 'core/image', [
'name' => 'img-book',
'label' => __( 'Book Lndscpe', 'm20t1' ),
'inline_style' => '.is-style-img-book img{width:var(--book-width);height:var(--book-height)}'
]);
// Image: Book portrait
register_block_style( 'core/image', [
'name' => 'img-book-portrait',
'label' => __( 'Book Portrait', 'm20t1' ),
'inline_style' => '.is-style-img-book-portrait img{width:var(--book-width);height:var(--book-height)}'
]);
// Image: Conform Text Style
register_block_style( 'core/image', [
'name' => 'img-conform',
'label' => __( 'Conform Text', 'm20t1' )
]);
// Gallery: Theme style
register_block_style( 'core/gallery', [
'name' => 'gallery-1',
'label' => __( 'Heavy Border', 'm20t1' ),
'inline_style' => '.is-style-gallery-1 .wp-block-image {
margin-bottom:1em !important;
}
.is-style-gallery-1 .wp-block-image img {
border:4px solid var(--wp--preset--color--primary-dark);
}
.is-style-gallery-1 .wp-block-image a[href] img:hover {
border:4px solid var(--wp--preset--color--primary);
box-shadow:5px 5px 0 0 #888;
}
.is-style-gallery-1 .wp-block-image a[href] img:active {
box-shadow:none;
}
.is-style-gallery-1 figure.wp-block-image:has(figcaption)::before {
height:0 !important;
}
.is-style-gallery-1 figure figcaption {
color:#666 !important;
font-size:0.8rem !important;
font-weight:500 !important;
margin-bottom:-1.5rem !important;
background:none !important;
text-shadow:none !important;
text-wrap:pretty;
}'
]);
// Gallery: Drop Shadow style
register_block_style( 'core/gallery', [
'name' => 'gallery-2',
'label' => __( 'Drop Shadow', 'm20t1' ),
'inline_style' => '.is-style-gallery-2 .wp-block-image {
margin-bottom:1em !important;
}
.is-style-gallery-2 .wp-block-image img {
box-shadow:0 3px 8px -2px #000c;
border-radius:3px;
}
.is-style-gallery-2 .wp-block-image a[href] img:hover {
box-shadow:0 8px 20px -1px #0008;
transform:scale(1.05, 1.05) !important;
}
.is-style-gallery-2 .wp-block-image a[href] img:active {
box-shadow:0 3px 6px -2px #0007;
}
.is-style-gallery-2 figure.wp-block-image:has(figcaption)::before {
height:0 !important;
}
.is-style-gallery-2 figure figcaption {
color:#666 !important;
font-size:0.8rem !important;
font-weight:500 !important;
margin-bottom:-1.5rem !important;
background:none !important;
text-shadow:none !important;
text-wrap:pretty;
}'
]);
// Gallery: No border style
register_block_style( 'core/gallery', [
'name' => 'gallery-3',
'label' => __( 'No Border', 'm20t1' ),
'inline_style' => '.is-style-gallery-3 .wp-block-image {
margin-bottom:1.2em !important;
}
.is-style-gallery-3 figure.wp-block-image:has(figcaption)::before {
height:0 !important;
}
.is-style-gallery-3 figure figcaption {
color:#666 !important;
font-size:0.8rem !important;
font-weight:500 !important;
margin-bottom:-1.5rem !important;
background:none !important;
text-shadow:none !important;
text-wrap:pretty;
}'
]);
// Latest Posts: Theme style
register_block_style( 'core/latest-posts', [
'name' => 'posts-theme',
'label' => __( 'Theme', 'm20t1' ),
'inline_style' => '.is-style-posts-theme {
max-width:var(--wp--style--global--wide-size);
margin:0 auto;
padding:0 !important;
& .wp-block-latest-posts__featured-image a:empty {
display:none;
}
& img {
border-radius:8px;
}
& a img {
cursor:pointer;
border:2px solid #0000;
transition:border 0.3s;
}
& a img:hover {
border-color:var(--wp--preset--color--primary);
}
& time {
color:#666;
}
& .wp-block-latest-posts__post-title {
display:block;
line-height:1.2;
height:2.5em;
font-weight:600;
overflow-y:hidden;
text-decoration:none !important;
}
& .wp-block-latest-posts__post-title:hover {
text-decoration:underline !important;
text-decoration-color:var(--wp--preset--color--primary) !important;
color:var(--wp--preset--color--primary) !important;
}
& .wp-block-latest-posts__post-excerpt {
font-size:1rem;
text-wrap:pretty;
}
}'
]);
// Cover Block: Stripe Fade background
register_block_style( 'core/cover', [
'name' => 'cover-stripe-fade',
'label' => __( 'Stripe Fade', 'm20t1' )
]);
// Media & Text Block: Image full width style
register_block_style( 'core/media-text', [
'name' => 'media-text-full',
'label' => __( 'Full Image', 'm20t1' ),
'inline_style' => '.is-style-media-text-full {
position:relative;
max-height:24em;
overflow:hidden;
display:flex !important;
align-items:center;
justify-content:center;
}
.is-style-media-text-full figure {
width:100%;
}
.is-style-media-text-full div {
position:absolute;
text-align:center;
}
.is-style-media-text-full p {
border-radius:12px;
text-wrap:pretty;
}'
]);
// Media & Text Block: Text overlap style
register_block_style( 'core/media-text', [
'name' => 'media-text-overlap',
'label' => __( 'Overlap', 'm20t1' ),
'inline_style' => '.is-style-media-text-overlap {
transform:translateX(-20px);
}
.is-style-media-text-overlap figure {
margin-right:130px;
}
.is-style-media-text-overlap figure img {
border-radius:14px;
}
.is-style-media-text-overlap div {
background-color:#eee3;
-webkit-backdrop-filter:blur(5px);
backdrop-filter:blur(5px);
border:1px solid #ddd7;
border-radius:14px;
height:92%;
transform:translateX(-40px);
}
.is-style-media-text-overlap.has-media-on-the-right div {
transform:translateX(40px);
}'
]);
});
// Add additional options to block editor elements
add_filter( 'register_block_type_args', function( $args, $block_type ) {
if ( in_array( $block_type, ['core/group', 'core/file', 'core/list-item', 'core/buttons', 'core/text', 'core/media-text', 'core/details', 'core/accordion', 'core/accordion-item', 'core/flipbox', 'core/table-of-contents', 'core/column', 'core/legacy-widget', 'core/cover', 'core/table', 'core/pullquote', 'core/icon', 'core/code', 'core/embed', 'core/video', 'core/math', 'core/separator', 'core/latest-posts', 'core/social-links', 'core/preformatted', 'core/legacy-widget', 'core/verse', 'core/calendar', 'core/search'], true ) ) {
$args['supports']['typography'] = true; // Add typography option
$args['supports']['filter']['duotone'] = true; // Add duotone filter
$args['supports']['shadow'] = true; // Add box shadow option
//$args['supports']['color'] = ['text' => true, 'background' => true, 'link' => true, 'gradients' => true]; // Add color options
}
// if ( 'core/heading' === $block_type ) $args['attributes']['levelOptions']['default'] = [ 2, 3, 4, 5, 6 ]; // Remove H1 option
return $args;
}, 10, 2 );
/////////////////////////////
// WordPress Setup
/////////////////////////////
// Get the version of m20T1 from style.css
define( 'THEME_VERSION', wp_get_theme()->get('Version') );
// Decactivate xml-rpc WordPress feature for security reasons
//add_filter( 'xmlrpc_enabled', '__return_false' );
//add_filter( 'load_configurator_on_page', '__return_true' );
// Enable WordPress features and register menus
add_action( 'after_setup_theme', function(){
// Add additional theme support
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'custom-line-height' );
add_theme_support( 'custom-spacing' );
add_theme_support( 'featured-content' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'customize-selective-refresh-widgets' );
add_theme_support( 'align-wide' );
add_theme_support( 'wp-block-styles' );
// Set featured image thumbnail size
the_post_thumbnail( 'medium' );
// Add additional image sizes
add_image_size( 'thumbnail-large', 300, 300, true ); // 300x300 Cropped
// Add excerpt support to pages
add_post_type_support( 'page', 'excerpt' );
// Custom background and header support
add_theme_support( 'custom-header', [ 'default-color' => 'fefefe', 'default-image' => '', 'width' => 300, 'height' => 60, 'flex-height' => true, 'flex-width' => true, 'default-text-color' => '', 'header-text' => true, 'uploads' => true ] );
add_theme_support( 'custom-background', [ 'default-image' => '', 'default-preset' => 'default', 'default-size' => 'cover', 'default-repeat' => 'repeat', 'default-attachment' => 'scroll' ] );
// Custom logo support
add_theme_support( 'custom-logo', [ 'flex-height' => true, 'flex-width' => true, 'header-text' => [ 'site-title', 'site-description' ], ] );
// Add HTML5 Support
add_theme_support( 'html5', [ 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption', 'style', 'script' ] );
// Set the different post formats that the author can select
//add_theme_support( 'post-formats', [ 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ] );
// Set the site navigation menus
register_nav_menu( 'primary', __( 'Primary Navigation', 'm20T1' ) );
register_nav_menu( 'secondary', __( 'Secondary Navigation', 'm20T1' ) );
register_nav_menu( 'tertiary', __( 'Tertiary Navigation', 'm20T1' ) );
});
// Enable styles and scripts
add_action( 'wp_enqueue_scripts', function(){
// Add Javascripts to the bottom of the page body
wp_enqueue_script( 'm20t1-scripts', get_template_directory_uri() . "/assets/scripts/scripts.js", [], THEME_VERSION, true );
// Add stylesheets to the HEAD metadata
wp_enqueue_style( 'm20t1-style', get_stylesheet_uri(), [], THEME_VERSION, 'all' );
// Remove post comments reply
wp_dequeue_script( 'comment-reply' );
// Remove WordPress block library CSS
wp_dequeue_style( 'wc-block-style' ); // WooCommerce
wp_dequeue_style( 'storefront-gutenberg-blocks' ); // Storefront
wp_dequeue_style( 'wp-block-library-theme' );
wp_deregister_style( 'wp-block-library-theme' );
//wp_dequeue_style( 'wp-block-library' );
//wp_deregister_style( 'wp-block-library' );
});
// Dashicons - Dashicons [class="dashicons dashicons-google"]
add_action( 'wp_print_styles', function(){
if (!is_admin_bar_showing() && !is_customize_preview()) {
wp_dequeue_style( 'dashicons' );
wp_deregister_style( 'dashicons' );
}
}, 100);
// Enable or disable WordPress features on initialize
add_action( 'init', function(){
// Add Category support to pages and attachments
register_taxonomy_for_object_type( 'category', 'page' );
register_taxonomy_for_object_type( 'category', 'attachment' );
// Add Tag support to pages and attachments
//register_taxonomy_for_object_type( 'post_tag', 'page' );
//register_taxonomy_for_object_type( 'post_tag', 'attachment' );
// Remove WordPress generated site Favicon and app icons in favor of my own metadata
remove_action( 'wp_head', 'wp_site_icon', 99 );
// Remove WordPress Emojis
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_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
//add_filter( 'wp_resource_hints', 'disable_emojis', 10, 2 );
// Remove RSS feed links
remove_action( 'wp_head', 'feed_links_extra', 3 );
//remove_action( 'wp_head', 'feed_links', 2 );
// Remove version number from the generator for security
remove_action( 'wp_head', 'wp_generator' );
// Remove canonical (use custom instead)
remove_action( 'wp_head', 'rel_canonical' );
// Remove shortlink
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 );
// Remove comments from embeds
remove_action( 'embed_content_meta', 'print_embed_comments_button' );
// Remove default robots call
remove_filter('wp_robots', 'wp_robots_max_image_preview_large');
// Enable the use of shortcodes in text widgets
add_filter( 'widget_text', 'do_shortcode' );
// Cycle through the ADDITIONAL_POST_TYPE array
foreach (ADDITIONAL_POST_TYPE as [$type, $type_plural, $icon, $subtitle]) {
// Add a custom post type to the editor
register_post_type( $type, [
'labels' => [
'name' => _x( $type_plural, 'm20t1' ),
'singular_name' => _x( $type, 'm20t1' ),
'menu_name' => _x( $type_plural, 'm20t1' ),
'name_admin_bar' => _x( $type, 'm20t1' ),
'add_new' => __( "Add {$type}" ),
'add_new_item' => __( "Add {$type}" ),
'new_item' => __( "New {$type}" ),
'edit_item' => __( "Edit {$type}" ),
'view_item' => __( "View {$type}" ),
'view_items' => __( "View {$type_plural}" ),
'all_items' => __( "All {$type_plural}" ),
'search_items' => __( "Search {$type_plural}" ),
'parent_item_colon' => __( "Parent {$type}:" ),
'not_found' => __( "No {$type_plural} found." ),
'not_found_in_trash' => __( "No {$type_plural} found in Trash." ),
'featured_image' => _x( "Featured Image", 'm20t1' ),
'set_featured_image' => _x( "Set cover image", 'm20t1' ),
'remove_featured_image' => _x( "Remove cover image", 'm20t1' ),
'use_featured_image' => _x( "Use as cover image", 'm20t1' ),
'archives' => _x( "{$type} archives", 'm20t1' ),
'attributes' => _x( "{$type} attributes", 'm20t1' ),
'insert_into_item' => _x( "Insert into {$type}",'m20t1' ),
'uploaded_to_this_item' => _x( "Uploaded to this {$type}", 'm20t1' ),
'filter_items_list' => _x( "Filter {$type} list", 'm20t1' ),
'items_list_navigation' => _x( "{$type} list navigation", 'm20t1' ),
'items_list' => _x( "{$type} list", 'm20t1' ),
'item_published' => _x( "{$type} published", 'm20t1' ),
'item_published_privately'=>_x( "{$type} published privately", 'm20t1' ),
'item_updated' => _x( "{$type} updated", 'm20t1' ),
'item_reverted_to_draft' => _x( "{$type} reverted to draft", 'm20t1' ),
'item_scheduled' => _x( "{$type} scheduled", 'm20t1' ),
'item_link' => _x( "{$type} link", 'm20t1' ),
'item_link_description' => _x( "A link to a {$type}", 'm20t1' ),
'uri_slug' => _x( rawurlencode(strtolower($type)), 'm20t1' ),
],
'rewrite' => [ 'slug' => rawurlencode(strtolower($type)) ],
'menu_position' => 20, // Below 'Pages'
'description' => $subtitle,
'menu_icon' => $icon,
'full_path' => get_page_by_path(rawurlencode(strtolower($type))),
'supports' => [ 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions', 'page-attributes', 'custom-fields' ],
'taxonomies' => [ 'category' ], // category, post_tag
'capability_type' => 'page',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'query_var' => true,
'exclude_from_search'=> false,
'has_archive' => true,
'hierarchical' => true,
'can_export' => true,
'map_meta_cap' => true,
'show_in_rest' => true
]);
// Display a different number of posts on this landing page
//add_filter( 'pre_get_posts', function(){
// $limit = (get_post_field( 'post_name' ) == $type) ? 2 : get_option('posts_per_page');
// set_query_var('posts_per_archive_page', $limit);
//});
}
});
// Append HTML metadata to the TOP of the page <head> tag
function m20t1_head() {
?>
<meta charset="<?=bloginfo('charset');?>">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<meta name="title" content="<?=bloginfo('name');?>">
<meta name="robots" content="max-image-preview:large">
<meta name="generator" content="m20T1 WordPress Theme by Ted Balmer">
<?php
}
// Append HTML metadata to the BOTTOM of the page <head> tag
add_action( 'wp_head', function(){
?>
<link rel="canonical" href="<?=esc_url((empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://" . ltrim("$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", "www."));?>">
<link rel="dns-prefetch" href="<?=esc_url(preg_replace("(^https?:)", '', home_url()));?>">
<link rel="pingback" href="<?=bloginfo('pingback_url');?>">
<link rel="Siteuri" href="<?=home_url();?>/" id="SiteURI">
<meta name="author" content="<?=get_the_author_meta('display_name', get_post_field ('post_author', get_the_ID()));?>">
<meta name="application-name" content="<?=bloginfo('name');?>">
<meta name="apple-mobile-web-app-title" content="<?=bloginfo('name');?>">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="description" content="<?=SEO_Excerpt(get_the_id());?>">
<meta name="format-detection" content="telephone=no">
<link rel="icon" href="<?=esc_url(home_url() . "/favicon.ico");?>" type="image/x-icon" sizes="any">
<link rel="icon" href="<?=esc_url(home_url() . "/favicon.svg");?>" type="image/svg+xml">
<link rel="apple-touch-icon" href="<?=esc_url(home_url() . "/apple-touch-icon.png");?>">
<link rel="manifest" href="<?=esc_url(home_url() . "/site.webmanifest");?>">
<meta property="og:locale" content="<?=get_bloginfo('language');?>">
<meta property="og:type" content="<?=(is_front_page()) ? "website" : "article";?>">
<meta property="og:site_name" content="<?=bloginfo('name');?>">
<meta property="og:url" content="<?=the_permalink();?>">
<meta property="og:title" content="<?=SEO_CharSwap(wp_title('', false, 'right')) ? SEO_CharSwap(wp_title('', false, 'right')) : bloginfo('name');?>">
<meta property="og:description" content="<?=SEO_Excerpt(get_the_id());?>">
<meta property="og:image" content="<?=SEO_Image(get_the_id());?>">
<meta property="og:image:type" content="image/<?=get_file_extension(SEO_Image(get_the_id()));?>">
<meta property="article:publisher" content="<?=get_the_author_meta('facebook', get_post_field ('post_author', get_the_ID()));?>">
<meta property="article:published_time" content="<?=get_the_date('c');?>">
<meta property="article:modified_time" content="<?=get_the_modified_date('c');?>">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@<?=trim(parse_url(get_the_author_meta('twitter', get_post_field ('post_author', get_the_ID())), PHP_URL_PATH), '/');?>">
<meta name="twitter:url" content="<?=the_permalink();?>">
<meta name="twitter:title" content="<?=SEO_CharSwap(wp_title('', false, 'right')) ? SEO_CharSwap(wp_title('', false, 'right')) : bloginfo('name');?>">
<meta name="twitter:description" content="<?=SEO_Excerpt(get_the_id());?>">
<meta name="twitter:image" content="<?=SEO_Image(get_the_id());?>">
<meta name="twitter:label1" content="Written by">
<meta name="twitter:data1" content="<?=get_the_author_meta('display_name', get_post_field ('post_author', get_the_ID()));?>">
<meta name="twitter:label2" content="Est. reading time">
<meta name="twitter:data2" content="<?=reading_time();?>">
<?=allow_html_metadata(get_option('head_metadata'));// Post user metadata ?>
<?=schemaJSONData();// Post Schema JSON ?>
<?php
});
// Append to the top of the page body tag
add_action( 'wp_body_open', function(){
echo allow_html_tags(get_option('body_top_html')); // Post user HTML
set_page_views(); // Page view counter
});
// Append to the bottom of the page body tag
add_action( 'wp_footer', function(){
?>
<template id="Search-Modal">
<h3 class="search-title">Search <?=bloginfo('name');?></h3>
<?=get_search_form(['search-modal']); // Load searchform.php ?>
<div class="search-categories">
<h4>Post Categories</h4>
<?=wp_list_categories(['orderby' => 'name', 'show_count' => false, 'title_li' => '']); ?>
</div>
<style>.dialog-search .dialog-content{transform:none}</style>
</template>
<template id="Contact-Modal">
<?=get_template_part('contactform'); // Load contactform.php ?>
</template>
<?php
echo allow_html_tags(get_option('body_bottom_html')); // Insert custom HTML from meta box
});
// Set the JPEG compression for images that are generated by WordPress (default 90)
add_filter( 'jpeg_quality', function(){
return 78; // 1-100
});
// Set the excerpt word length
add_filter( 'excerpt_length', function(){
return get_option('excerpt_length') ? get_option('excerpt_length') : EXCERPT_LENGTH;
});
// Add a 'Continue Reading' link to excerpts
add_filter( 'excerpt_more', function(){
return '<span class="entry-read-more" aria-label="Read more">'.MORE_TEXT.'</span>';
});
// Add addition file types uploadable to the Media Library
add_filter( 'upload_mimes', function($mimes){
$mimes['svg|svgz'] = 'image/svg+xml'; // SVG image
$mimes['txt|md'] = 'text/plain'; // TXT document
$mimes['vcard|vcf'] = 'text/vcard'; // vCard data
$mimes['ics|ical'] = 'text/calendar'; // iCalendar data
$mimes['woff|woff2'] = 'font/woff2|application/octet-stream|font/x-woff2'; // WOFF2 font
$mimes['glb|gltf'] = 'model/gltf+json|model/gltf-binary|model/gltf.binary'; // glTF WebGL model
return $mimes;
}, 1, 1);
// Override file check for certain file types when uploading to the Media Library
add_filter( 'wp_check_filetype_and_ext', function($types, $file, $filename, $mimes){
if ( false !== strpos( $filename, '.glb' ) ) {
$types['ext'] = 'glb';
$types['type'] = 'model/gltf-binary';
}
if ( false !== strpos( $filename, '.txt' ) ) {
$types['ext'] = 'txt|md';
$types['type'] = 'text/plain';
}
if ( false !== strpos( $filename, '.woff2' ) ) {
$types['ext'] = 'woff2';
$types['type'] = 'font/woff2|application/octet-stream|font/x-woff2';
}
return $types;
}, 10, 4);
// Set a text fallback to the custom image logo hook
add_filter( 'get_custom_logo', function(){
if (has_custom_logo()) { // Use image logo
return wp_get_attachment_image( get_theme_mod('custom_logo'), 'full', false, ['class' => 'custom-logo', 'srcset' => '', 'itemprop' => 'image', 'fetchpriority' => 'high', 'alt' => 'Logo', 'decoding' => 'async'] ) . '<span class="visual-hidden" itemprop="name headline">' . get_bloginfo('name') . '</span>';
} else { // No logo, use site title
return '<span itemprop="name headline">' . get_bloginfo('name') . '</span>';
}
});
// Remove srcset from SVG images so SVG files in img tags will display correctly
add_filter( 'wp_calculate_image_sizes', function( string $sizes, array $size, $image_src = null ){
$image_type = end(explode('.', $image_src));
if ( $image_type === 'svg' || $image_type === 'svgz' ) {
return null;
} else {
return $sizes;
}
}, 10, 3 );
/////////////////////////////
// Sidebar and Widgets
/////////////////////////////
// Register the sidebar widgets
add_action( 'widgets_init', function(){
// Primary Sidebar - Full blog page
register_sidebar([
'id' => 'primary',
'name' => __( 'Blog Sidebar', 'm20T1' ),
'description' => __( 'Blog page sidebar widgets.' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
]);
// Secondary Sidebar - Archive Pages
register_sidebar([
'id' => 'secondary',
'name' => __( 'Archive Sidebar', 'm20T1' ),
'description' => __( 'Archive pages sidebar widgets.' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
]);
// Tertiary Sidebar - Search Results
register_sidebar([
'id' => 'tertiary',
'name' => __( 'Search Page Sidebar', 'm20T1' ),
'description' => __( 'Search results page sidebar widgets.' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
]);
// Single Post Widgets
register_sidebar([
'id' => 'singlepost',
'name' => __( 'Single Post Widgets', 'm20T1' ),
'description' => __( 'Widgets below a single blog post.' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
]);
// Front page Widgets
register_sidebar([
'id' => 'frontpage',
'name' => __( 'Front Page Widgets', 'm20T1' ),
'description' => __( 'Widgets on the bottom of the front page and landing pages.' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
]);
// Page Widgets
register_sidebar([
'id' => 'singlepage',
'name' => __( 'Page Widgets', 'm20T1' ),
'description' => __( 'Widgets below the contents on a single web page and attachment pages.' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
]);
// Page Header Widgets
register_sidebar([
'id' => 'header',
'name' => __( 'Header Widgets', 'm20T1' ),
'description' => __( 'The page header widgets.' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<p class="widget-title">',
'after_title' => '</p>',
]);
// Page Footer Widgets
register_sidebar([
'id' => 'footer',
'name' => __( 'Footer Widgets', 'm20T1' ),
'description' => __( 'The page footer widgets.' ),
'before_widget' => '<nav id="%1$s" class="widget %2$s">',
'after_widget' => '</nav>',
'before_title' => '<p class="widget-title">',
'after_title' => '</p>',
]);
});
// Get 'Widgets_Slug' Custom Field which changes the sidebar selection
// SLUGS: primary, secondary, tertiary, singlepost, frontpage, singlepage, header, footer
function selectSidebarCustomField( $id, $default ) {
$key = get_post_meta( $id, 'Widgets_Slug', true );
return empty($key) ? $default : sanitize_text_field($key);
}
/////////////////////////////
// Navigation
/////////////////////////////
// Display the menu/navigation links as a list
function menu_nav_list( $menu, $id ) {
wp_nav_menu([
'menu' => $menu,
'container' => 'nav',
'container_class' => 'nav-'.$id,
'container_id' => $id,
'container_aria_label' => $menu,
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<menu id="%1$s" class="%2$s">%3$s</menu>',