/
functions.php
executable file
·2054 lines (1839 loc) · 74.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
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
//* Start the engine
include_once( get_template_directory() . '/lib/init.php' );
//* Child theme (do not remove)
define( 'CHILD_THEME_NAME', 'Coastal_Wh' );
define( 'CHILD_THEME_URL', 'http://www.stnsvn.com/' );
define( 'CHILD_THEME_VERSION', '2.1.1' );
//Configure one click install
require get_stylesheet_directory() .'/lib/plugins/radium-one-click-demo-install/init.php';
//* Enqueue Google Fonts
add_action( 'wp_enqueue_scripts', 'coastal_google_fonts' );
function coastal_google_fonts() {
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Lato:300,400,700|Montserrat:400,700', array(), CHILD_THEME_VERSION );
}
/* Remove Admin Bar
/* ------------------------------------ */
add_filter('show_admin_bar', '__return_false');
//Initialize the update checker.
// require ('lib/plugins/automatic-theme-updates/theme-updates/theme-update-checker.php');
// $coastal_update_checker = new ThemeUpdateChecker(
// 'coastal',
// 'http://updates.stnsvn.com/coastal/coastal-theme-updates.json'
// );
//Include shortcodes
require_once('lib/shortcodes.php');
//Configure ACF PRO
// 1. customize ACF path
add_filter('acf/settings/path', 'coastal_acf_settings_path');
function coastal_acf_settings_path( $path ) {
// update path
$path = get_stylesheet_directory() . '/lib/plugins/advanced-custom-fields-pro/';
// return
return $path;
}
// 2. customize ACF dir
add_filter('acf/settings/dir', 'coastal_acf_settings_dir');
function coastal_acf_settings_dir( $dir ) {
// update path
$dir = get_stylesheet_directory_uri() . '/lib/plugins/advanced-custom-fields-pro/';
// return
return $dir;
}
// 3. Hide ACF field group menu item
add_filter('acf/settings/show_admin', '__return_false');
// 4. Include ACF
include_once( get_stylesheet_directory() . '/lib/plugins/advanced-custom-fields-pro/acf.php' );
require_once('lib/plugins/coastal-acf-pro-settings.php');
//Configure ACF
define( 'ACF_LITE', false );
include_once('lib/plugins/advanced-custom-fields/acf.php');
require_once('lib/plugins/coastal-acf-settings.php');
//Configure third party plugins
require_once('lib/plugins/tgm-plugin-activation/tgm-plugin-activation-config.php');
//* Register images
add_image_size( 'blog-featured', 840, 2000, FALSE );
add_image_size( 'latest-featured', 767, 850, TRUE );
//* Add HTML5 markup structure
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) );
//* Add viewport meta tag for mobile browsers
add_theme_support( 'genesis-responsive-viewport' );
//*Enqueue ACF admin scripts
function load_custom_wp_admin_scripts() {
wp_enqueue_script( 'acf_script', get_stylesheet_directory_uri() . '/lib/js/admin-scripts.js', array( 'jquery' ) );
}
add_action( 'acf/input/admin_footer', 'load_custom_wp_admin_scripts' );
//* Enqueue Viewport Units Buggyfill and theme JS
function coastal_enqueue_scripts() {
wp_enqueue_script( 'isotopes', get_stylesheet_directory_uri() . '/lib/js/jquery.isotope.min.js', '', '', true );
wp_enqueue_script( 'viewport-units-buggyfill', get_stylesheet_directory_uri() . '/lib/js/viewport-units-buggyfill.js', '', '0.5.0', true );
wp_enqueue_script( 'viewport-units-buggyfill.hacks', get_stylesheet_directory_uri() . '/lib/js/viewport-units-buggyfill.hacks.js', '', '0.5.0', true );
wp_enqueue_script( 'viewport-units-buggyfill-hacks-init', get_stylesheet_directory_uri() . '/lib/js/viewport-units-buggyfill-hacks-init.js', '', '0.5.0', true );
wp_enqueue_script('jquery-masonry');
wp_enqueue_script( 'main', get_stylesheet_directory_uri() . '/lib/js/main.js', '', '0.1.0', true );
}
add_action( 'wp_enqueue_scripts', 'coastal_enqueue_scripts' );
// Set default attachment display settings
function coastal_setup() {
// Set default values for the upload media box
update_option('image_default_align', 'center' );
update_option('image_default_link_type', 'none' );
update_option('image_default_size', 'full' );
}
add_action('after_setup_theme', 'coastal_setup');
//Set content width
if ( ! isset( $content_width ) )
$content_width = 840;
//* Set default layout as full width
genesis_set_default_layout( 'full-width-content' );
/* Header Structure */
add_action( 'genesis_before_header', 'coastal_header_fill' );
/**
* This function adds the fill bar at the top of the site.
*/
function coastal_header_fill() {
echo '<div class="header-fill" id="top">' . '</div>';
}
//*Add theme support for woocommerce
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
// Display 24 products per page. Goes in functions.php
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );
// Change number or products per row to 3
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 3; // 3 products per row
}
}
//Add featured image support to shop page
add_action('woocommerce_before_main_content', 'coastal_shop_featured', 25);
function coastal_shop_featured() {
if ( class_exists( 'WooCommerce' ) ) {
$page_id = wc_get_page_id('shop');
if ( is_shop() && has_post_thumbnail($page_id) ) {
echo get_the_post_thumbnail( $page_id, 'full' );
}
}
}
//Add shop class to shop page
if (class_exists( 'WooCommerce' )) {
add_filter( 'body_class', 'coastal_shop_class' );
function coastal_shop_class( $classes ) {
if ( is_shop( ) ) {
$classes[] = 'shop-page';
}
return $classes;
}
}
//Fix smooth scroll conflict with WC
add_action('wp_footer','coastal_WCSmoothScrollFix');
function coastal_WCSmoothScrollFix() {
if (class_exists( 'WooCommerce' ) && is_product()) {
wp_localize_script( 'main', 'SmoothScroll', array('scroll' => '1') );
} else {
wp_localize_script( 'main', 'SmoothScroll', array('scroll' => '0') );
}
}
//Add placeholder text to WooCommerce fields
if (class_exists( 'WooCommerce' )) {
add_action( 'genesis_before_footer', 'coastal_review_inputs' );
function coastal_review_inputs() {
if (is_product()) {
?> <script>
jQuery(document).ready(function() {
jQuery('#author').attr('placeholder','Name');
jQuery('#email').attr('placeholder','Email');
});
</script>
<?php
}
}
}
// Control number of footer columns
remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
add_theme_support('genesis-footer-widgets', 4);
add_action( 'genesis_before_footer', 'coastal_footer_widget_areas' );
function coastal_footer_widget_areas() {
global $footer_col_number, $footer_widget_columns;
$footer_col_number = 3; //Add a default for column number so there's no need to add value for 3 columns
$footer_widget_columns = get_theme_mod( 'footer_col_number', 'footer-col-varied-3' );//Get column number value from theme customizer
switch ($footer_widget_columns) { //For columns 2, 3, 4: Adds a class to reflect new style for width, which should no longer be a varied width
case 'footer-col-1':
$cs_col_class = "one-col";
$footer_col_number = 1;
break;
case 'footer-col-2':
$cs_col_class = "one-2-cols";
$footer_col_number = 2;
break;
case 'footer-col-3':
$cs_col_class = "one-3-cols";
break;
case 'footer-col-4':
$cs_col_class = "one-4-cols";
$footer_col_number = 4;
break;
default:
}
$cs_footer_widgets = $footer_col_number;
if ( ! is_active_sidebar( 'footer-1' ) )
return;
$cs_inside = '';
$cs_output = '';
$cs_counter = 1;
while ( $cs_counter <= $cs_footer_widgets ) {
ob_start();
dynamic_sidebar( 'footer-' . $cs_counter );
$cs_widgets = ob_get_clean();
if ($footer_widget_columns == "footer-col-varied-3") {
$cs_inside .= sprintf( '<div class="footer-widgets-%d widget-area">%s</div>', $cs_counter, $cs_widgets );
}
else {
$cs_inside .= sprintf( '<div class="col %s widget-area">%s</div>', $cs_col_class, $cs_widgets );
}
$cs_counter++;
}
if ( $cs_inside ) {
$cs_output .= genesis_markup( array(
'html5' => '<div %s>',
'xhtml' => '<div id="footer-widgets" class="footer-widgets">',
'context' => 'footer-widgets',
) );
$cs_output .= genesis_structural_wrap( 'footer-widgets', 'open', 0 );
$cs_output .= $cs_inside;
$cs_output .= genesis_structural_wrap( 'footer-widgets', 'close', 0 );
$cs_output .= '</div>';
}
echo $cs_output; //**Removed apply filters and directly echo the output
}
//* Full width footer widget area
genesis_register_sidebar (
array(
'id' => 'full-width-footer',
'name' => _('Full Width Footer'),
'description' => __('This is a full width widget area that displays before the footer.'),
)
);
//* Add a full-width footer widget area
add_action( 'genesis_before_footer', 'coastal_full_width_footer_widget', 5 );
function coastal_full_width_footer_widget() {
genesis_widget_area( 'full-width-footer',
array(
'before' => '<div class="full-width-footer widget-area">',
'after' => '</div>',
)
);
}
//* Reposition the primary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_header', 'genesis_do_nav' );
//* Reposition the secondary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_before', 'coastal_do_subnav' );
function coastal_do_subnav() {
echo '<div class="nav-container nav-transparent">';
genesis_do_subnav();
echo '</div>';
}
//* Register navigation menus
add_theme_support ( 'genesis-menus' ,
array (
'primary' => __('Primary Navigation Menu') ,
'secondary' => __('Secondary Navigation Menu') ,
)
);
//Enable or Disable transparency for secondary menu
add_action('wp_footer','coastal_transparent_secondary_nav');
function coastal_transparent_secondary_nav() {
if ( has_nav_menu( 'secondary' ) ) {
if (is_front_page()) {
$coastal_activate_transparent_secondary_menu = get_theme_mod( 'transparent_secondary_menu', 0 );
} else {
$coastal_activate_transparent_secondary_menu = 1;
}
$coastal_activate_sticky_secondary_menu = get_theme_mod( 'sticky_secondary_menu', 0 );
wp_localize_script( 'main', 'SecondaryNavParams', array('transparency' => $coastal_activate_transparent_secondary_menu , 'sticky' => $coastal_activate_sticky_secondary_menu) );
} else {
wp_localize_script( 'main', 'SecondaryNavParams', array('transparency' => '1' , 'sticky' => '1') );
}
}
/** Add support for custom header **/
add_action( 'after_setup_theme', 'coastal_register_header', 5 );
function coastal_register_header() {
add_theme_support( 'genesis-custom-header', array( 'width' => '1400', 'height' => '800' ) );
}
/*Remove existing custom header function*/
remove_action( 'wp_head', 'genesis_custom_header_style', 10 );
add_action( 'wp_head', 'coastal_custom_header_style', 10 );
/**
* Add custom header callback.
* It outputs special CSS to the document head, modifying the look of the header based on user input.
* @since 1.0.0
* @uses genesis_html() Check for HTML5 support.
* @return null Return null on if custom header not supported, user specified own callback, or no options set.
*/
function coastal_custom_header_style() {
//* Do nothing if custom header not supported
if ( ! current_theme_supports( 'custom-header' ) )
return;
//* Do nothing if user specifies their own callback
if ( get_theme_support( 'custom-header', 'wp-head-callback' ) )
return;
$output = '';
$header_image = get_header_image();
global $text_color;
if (is_front_page()) {
if (get_theme_mod('header_txt_color') != "") {
$text_color = ltrim (get_theme_mod('header_txt_color', '#333'), '#');//get_header_textcolor();
}
else {
$text_color = "333";
}
}
else {
$text_color = get_header_textcolor();
}
//* If no options set, don't waste the output. Do nothing.
if ( empty( $header_image ) && ! display_header_text() && $text_color === get_theme_support( 'custom-header', 'default-text-color' ) )
return;
$header_selector = get_theme_support( 'custom-header', 'header-selector' );
$title_selector = genesis_html5() ? '.custom-header .site-title' : '.custom-header #title';
$desc_selector = genesis_html5() ? '.custom-header .site-description' : '.custom-header #description';
//* Header selector fallback
if ( ! $header_selector )
$header_selector = genesis_html5() ? '.custom-header .site-header' : '.custom-header #header';
//* Header image CSS, if exists
if ( $header_image && is_front_page() )
$output .= sprintf( '%s { background: url(%s) no-repeat; background-size: cover!important; height: 800px; height: 100vh; background-attachment: fixed; }', $header_selector, esc_url( $header_image ) );
//* Header image CSS, if exists
if ( $header_image && is_404() )
$output .= sprintf( '%s { background: url(%s) no-repeat; background-size: cover!important; height: 800px; height: 100vh; background-attachment: fixed; }', $header_selector, esc_url( $header_image ) );
//* Header text color CSS, if showing text
if ( display_header_text() && $text_color !== get_theme_support( 'custom-header', 'default-text-color' ) )
$output .= sprintf( '%2$s a, %2$s a:hover, %3$s { color: #%1$s !important; }', esc_html( $text_color ), esc_html( $title_selector ), esc_html( $desc_selector ) );
if ( $output )
printf( '<style type="text/css">%s</style>' . "\n", $output );
}
//*Manage Genesis defaults
//* Unregister sidebar/content layout setting
genesis_unregister_layout( 'sidebar-content' );
//* Unregister content/sidebar/sidebar layout setting
genesis_unregister_layout( 'content-sidebar-sidebar' );
//* Unregister sidebar/sidebar/content layout setting
genesis_unregister_layout( 'sidebar-sidebar-content' );
//* Unregister sidebar/content/sidebar layout setting
genesis_unregister_layout( 'sidebar-content-sidebar' );
//* Remove breadcrumbs
remove_theme_support( 'genesis-breadcrumbs' );
//* Remove the header right widget area
unregister_sidebar( 'header-right' );
//* Remove sidebar alt widget area
unregister_sidebar( 'sidebar-alt' );
// Removing sections from Genesis Theme Settings page
if (is_admin()) :
function coastal_remove_settings($pagehook) {
remove_meta_box( 'genesis-theme-settings-blogpage', $pagehook, 'main' );
}
add_action( 'genesis_theme_settings_metaboxes' , 'coastal_remove_settings');
endif;
/** Force full width layout */
add_filter( 'genesis_pre_get_option_site_layout', 'stnsvn_do_layout' );
function stnsvn_do_layout( $opt ) {
if ( is_page() ) { // Modify the conditions to apply the layout to here
$opt = 'full-width-content'; // You can change this to any Genesis layout
return $opt;
}
}
/* Footer Structure */
//* Customize the entire footer
remove_action( 'genesis_footer', 'genesis_do_footer' );
add_action( 'genesis_footer', 'coastal_custom_footer' );
function coastal_custom_footer() {
$coastal_display_copyright = get_theme_mod( 'copyright-footer' );
$coastal_stnsvn_credit = get_theme_mod( 'stnsvn-credit' );
if ( $coastal_display_copyright == '' ) {
echo '<p>Copyright ' , date("Y ") , bloginfo("name");
}
else {
echo '<p>' , get_theme_mod( 'copyright-footer' ) , '</p>';
}
}
/*Blog Structure*/
// Add id="content" attributes to <main> element
add_filter( 'genesis_attr_content', 'stnsvn_attr_content' );
function stnsvn_attr_content( $attr ) {
$attr['id'] = 'index-content';
return $attr;
}
//Enable infinite scroll
function stnsvn_infinite_scroll_init() {
add_theme_support( 'infinite-scroll', array(
'container' => 'index-content',
'footer' => false,
'type' => 'click',
'footer_widgets' => true,
'wrapper' => true,
'render' => 'genesis_do_loop'
) );
}
add_action( 'after_setup_theme', 'stnsvn_infinite_scroll_init' );
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'infinite-scroll' ) ) :
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' );
else :
// do nothing
endif;
//* Customize the post info function
add_filter( 'genesis_post_info', 'coastal_info_filter' );
function coastal_info_filter($post_info) {
$coastal_display_date = get_theme_mod( 'display_post_date', 1 );
$coastal_display_byline = get_theme_mod( 'display_byline', 0 );
$coastal_display_comment_count = get_theme_mod( 'display_comment_count', 0 );
$blog_post_author="";$blog_post_date = ""; $blog_post_comment = "";
if (is_singular('portfolio') ){
//do nothing
}
else {
if ( $coastal_display_date != '' ) {
if ($coastal_display_byline == '' && $coastal_display_comment_count == '' ){
$blog_post_date = '[post_date]';
}
else {
$blog_post_date = '[post_date] • ';
}
}
if ( $coastal_display_byline != '' ) {
if ( $coastal_display_comment_count == '' ) {
$blog_post_author = '[post_author_posts_link]';
}
else {
$blog_post_author = '[post_author_posts_link] • ' ;
}
}
if ( $coastal_display_comment_count != '' ) {
$blog_post_comment = '[post_comments]';
}
$post_info = $blog_post_date.$blog_post_author.$blog_post_comment;
return $post_info;
}
}
//*Modify the footer post meta
add_filter( 'genesis_post_meta', 'coastal_post_meta_filter' );
function coastal_post_meta_filter($post_meta) {
$post_meta = '[post_categories before="'.__('Filed Under').': "] [post_tags before="'.__('Tagged with').': "]';
if ( is_singular( 'post' )) {
$coastal_display_categories = get_theme_mod( 'single_display_categories' );
$coastal_display_tags = get_theme_mod( 'single_display_tags' );
$blog_meta_categories = ""; $blog_meta_tags = "";
if ( $coastal_display_categories != '' ) {
$blog_meta_categories = '[post_categories before="'.__('Filed Under: ').'"]';
}
if ( $coastal_display_tags != '' ) {
$blog_meta_tags = ' [post_tags before="'.__('Tagged with: ').'"]';
}
$post_meta = $blog_meta_categories . $blog_meta_tags;
return $post_meta;
}
}
//* Modify the Genesis content limit read more link
add_filter( 'get_the_content_more_link', 'coastal_more_link' );
function coastal_more_link() {
return '... <a class="more-link" href="' . get_permalink() . '">'.__('Read More').'</a>';
}
//* Hide the WordPress read more link for custom excerpts
add_filter( 'excerpt_more', 'coastal_custom_excerpt_more' );
function coastal_custom_excerpt_more( $more ) {
//remove the default read more
}
//* Add custom read more for custom excerpts
add_action('genesis_entry_content', 'cstl2_custom_excerpt_more', 20);
function cstl2_custom_excerpt_more() {
$archive_style = genesis_get_option('content_archive');
if ( $archive_style == 'excerpts' ) {
if (is_archive() or is_home() or is_search()) {
echo '<a href="' . get_permalink() . '" class="more-link custom-more">' . __( 'Read More' ) . '</a>';
}
}
}
//Blog Layout
add_filter( 'genesis_pre_get_option_site_layout', 'coastal_blog_layout' );
function coastal_blog_layout( $opt ) {
if ( is_home() || is_single()) {
$opt = get_theme_mod( 'blog_layout' );
return $opt;
}
}
//**Excerpt Length
add_filter( 'excerpt_length', 'coastal_excerpt_length' );
function coastal_excerpt_length( $length ) {
$displayed_content = get_theme_mod( 'post_excerpt_limit' );
if ($displayed_content != "") {
return (int)$displayed_content; // pull first 50 words
}
else {
return 400;
}
}
//* Manage featured image display
add_action( 'genesis_entry_content', 'featured_post_image', 8 );
function featured_post_image() {
if ( is_page() || is_singular('portfolio') || is_page_template( 'portfolio-page.php' )) {
//Do nothing
} else {
//Display on postsis enabled in customizer
if (is_singular( 'post' )){
$display_featured_img = get_theme_mod('single_display_featured_image', 1);
if ($display_featured_img != "") {
the_post_thumbnail('blog-featured');
}
}
else {
//display on other templates
the_post_thumbnail('blog-featured');
}
}
}
//Display featured image on single pages
add_action( 'genesis_entry_header', 'coastal_page_featured_image', 5 );
function coastal_page_featured_image() {
if ( is_page() && has_post_thumbnail() && !is_page_template( 'portfolio-page.php' ) ) {
the_post_thumbnail('blog-featured');
}
}
//* Style pagination
add_filter( 'genesis_prev_link_text', 'stnsvn_prev_link_text' );
function stnsvn_prev_link_text() {
$prevlink = 'Newer';
return $prevlink;
}
add_filter( 'genesis_next_link_text', 'stnsvn_next_link_text' );
function stnsvn_next_link_text() {
$nextlink = 'Older';
return $nextlink;
}
/*Add share section to blog posts*/
add_action( 'genesis_entry_footer', 'blog_share_box', 10 );
function blog_share_box() {
if ( is_home() ) {
$display_blog_share_box = get_theme_mod( 'display_share_buttons', 1 );
if ( $display_blog_share_box != '') {
echo '
<div class="blog-share-box">
<h1>' , _e('Share') , '</h1>
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook">Facebook</a>
<a class="addthis_button_google_plusone_share">Google+</a>
<a class="addthis_button_twitter">Twitter</a>
<a class="addthis_button_pinterest_share">Pinterest</a>
<a class="addthis_button_email">Email</a>
</div>
<!-- AddThis Button BEGIN -->
<script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid='.get_theme_mod( 'coastal_addthis_pub_id' ).'"></script>
<!-- AddThis Button END -->
</div>';}
}
elseif ( is_singular('post') ) {
$display_single_blog_share_box = get_theme_mod( 'single_display_share_buttons', 1 );
if ( $display_single_blog_share_box != '') {
echo '
<div class="blog-share-box">
<h1>' , _e('Share') , '</h1>
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook">Facebook</a>
<a class="addthis_button_google_plusone_share">Google+</a>
<a class="addthis_button_twitter">Twitter</a>
<a class="addthis_button_pinterest_share">Pinterest</a>
<a class="addthis_button_email">Email</a>
</div>
<!-- AddThis Button BEGIN -->
<script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid='.get_theme_mod( 'coastal_addthis_pub_id' ).'"></script>
<!-- AddThis Button END -->
</div>';
}
}
else {
if ( is_singular('portfolio') ) {
echo '
<div class="blog-share-box">
<h1>' , _e('Share') , '</h1>
<div class="addthis_toolbox addthis_default_style">
<a class="addthis_button_facebook">Facebook</a>
<a class="addthis_button_google_plusone_share">Google+</a>
<a class="addthis_button_twitter">Twitter</a>
<a class="addthis_button_pinterest_share">Pinterest</a>
<a class="addthis_button_email">Email</a>
</div>
<!-- AddThis Button BEGIN -->
<script type="text/javascript">var addthis_config = {"data_track_addressbar":false};</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid='.get_theme_mod( 'coastal_addthis_pub_id' ).'"></script>
<!-- AddThis Button END -->
</div>';
}
}
}
//Post comments
// Reposition comment form
remove_action( 'genesis_comment_form', 'genesis_do_comment_form' );
add_action( 'genesis_before_comments', 'genesis_do_comment_form' );
//* Modify comments title text in comments
add_filter( 'comment_form_defaults', 'stnsvn_comment_form_defaults' );
function stnsvn_comment_form_defaults( $defaults ) {
$defaults['title_reply'] = __( 'Comments' );
return $defaults;
}
add_filter( 'genesis_title_comments', 'sp_genesis_title_comments' );
function sp_genesis_title_comments() {
$title = '';
return $title;
}
//* Remove comment form allowed tags
add_filter( 'comment_form_defaults', 'stnsvn_remove_comment_form_allowed_tags' );
function stnsvn_remove_comment_form_allowed_tags( $defaults ) {
$defaults['comment_notes_after'] = '';
return $defaults;
}
//Edit comment form placeholder text
add_filter( 'comment_form_default_fields', 'stnsvn_comment_placeholders' );
function stnsvn_comment_placeholders( $fields )
{
$fields['author'] = str_replace(
'<input',
'<input placeholder="'
. _x(
'Name',
'comment form placeholder',
'theme_text_domain'
)
. '"',
$fields['author']
);
$fields['email'] = str_replace(
'<input id="email" name="email" type="email"',
'<input type="email" placeholder="'.__('Email').'" id="email" name="email"',
$fields['email']
);
$fields['url'] = str_replace(
'<input id="url" name="url" type="url"',
'<input placeholder="'.__('Url').'" id="url" name="url" type="url"',
$fields['url']
);
return $fields;
}
//*Setup content page template
add_action( 'genesis_before_footer', 'back_to_top', 8 );
function back_to_top() {
if( is_page_template( 'portfolio-page.php' ) && !is_front_page()) { ?>
<div class="back-to-top">
<a href="<?php echo home_url(); ?>">
<h4 class="button"><?php _e('Go Back')?></h4>
</a>
</div>
<?php }
}
//Setup Go Back button on single posts
add_action( 'genesis_after_comments', 'back_to_blog', 8);
function back_to_blog() {
$display_go_back = get_theme_mod('single_display_go_back', 1);
if( is_singular( 'post') && $display_go_back == 1 ) { ?>
<div class="back-to-top">
<a href="<?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>">
<h4 class="button"><?php _e('Back to Blog');?></h4>
</a>
</div>
<?php }
}
//* Remove Edit Link
add_filter( 'edit_post_link', '__return_false' );
//* Enable redirect for home page subpages
function homepage_template_redirect()
{
if( is_page_template( 'page-home-section.php' ))
{
wp_redirect( home_url( '/' ) );
exit();
}
}
add_action( 'template_redirect', 'homepage_template_redirect' );
//********************* Portfolio post type ***************//
function coastal_portfolio() {
$labels = array(
'name' => _x( 'Portfolio', 'post type general name' ),
'singular_name' => _x( 'Portfolio', 'post type singular name' ),
'add_new' => _x( 'Add New', 'portfolio' ),
'add_new_item' => __( 'Add New Portfolio Item' ),
'edit_item' => __( 'Edit Portfolio Item' ),
'new_item' => __( 'New Portfolio Item' ),
'all_items' => __( 'All Portfolio Items' ),
'view_item' => __( 'View Portfolio Item' ),
'search_items' => __( 'Search Portfolio Items' ),
'not_found' => __( 'No Portfolio Items found' ),
'not_found_in_trash' => __( 'No Portfolio Items found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => __( 'Portfolio' )
);
$args = array(
'labels' => $labels,
'description' => __('Holds all portfolio items'),
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
);
register_post_type( 'portfolio', $args );
}
add_action( 'init', 'coastal_portfolio' );
function create_portfolio_category () {
// Add category taxonomy
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'Categories' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'portfolio-category' ),
);
register_taxonomy( 'portfolio_category', array( 'portfolio' ), $args );
}
add_action( 'init', 'create_portfolio_category', 0 );
//* Enable theme customizer and settings
/**
* Adds the individual sections, settings, and controls to the theme customizer
*/
function coastal_customizer( $wp_customize ) {
// Remove unused sections
$wp_customize->remove_section( 'colors');
$wp_customize->remove_section( 'background_image');
$wp_customize->remove_control( 'display_header_text');
$wp_customize->remove_section( 'genesis_layout');
$wp_customize->remove_section( 'static_front_page');
$wp_customize->remove_control( 'genesis_content_archive_thumbnail');
$wp_customize->remove_control( 'genesis_image_size');
$wp_customize->remove_control( 'genesis_image_alignment');
$wp_customize->remove_control( 'genesis_posts_nav');
$wp_customize->remove_section( 'genesis_archives');
// Update postMessage on existing settings
$wp_customize->get_setting('blogname')->transport='postMessage';
$wp_customize->get_setting('blogdescription')->transport='postMessage';
//-----------------------Landing Header Section -----------------------//
// Update description on header image section
$wp_customize->get_section('header_image')->title=__('Landing Header');
$wp_customize->get_section('header_image')->priority=20;
$wp_customize->get_control('header_image')->priority=20;
//Homepage header headline text box
$wp_customize->add_setting(
'header-headline-box',
array(
'transport' => 'postMessage',
'sanitize_callback' => 'coastal_sanitize_text',
)
);
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'header-headline-box',
array(
'label' => __('Headline Text'),
'section' => 'header_image',
'settings' => 'header-headline-box',
'type' => 'text',
'description' => __('Use this field to display a boxed headline in the header section'),
)
)
);
//Homepage header text box
$wp_customize->add_setting(
'header-textbox',
array(
'transport' => 'postMessage',
'sanitize_callback' => 'coastal_sanitize_text',
)
);
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'header-textbox',
array(
'label' => __('Header Overlay Text'),
'section' => 'header_image',
'settings' => 'header-textbox',
'type' => 'textarea',
'description' => __('Use this field to add any additional overlay content to the header area, like a button or a call to action. Accepts html tags like 〈h1〉〈strong〉〈img〉〈a〉 etc.'),
)
)
);
//Homepage Header Text Color
$wp_customize->add_setting(
'header_txt_color',
array(
'default' => '#333',
'sanitize_callback' => 'sanitize_hex_color',
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'header_txt_color',
array(
'label' => __('Homepage Header Text Color'),
'section' => 'header_image',
'settings' => 'header_txt_color',
)
)
);
//Control fixed background
$wp_customize->add_setting(
'fix_header',
array(
'sanitize_callback' => 'sanitize_checkbox',
'transport' => 'postMessage',
)
);
$wp_customize->add_control(
'fix_header',
array(
'type' => 'checkbox',
'label' => __('Fix header image on scroll'),
'section' => 'header_image',
)
);
//Logo upload section
$wp_customize->add_setting(
'logo_upload',
array(
'transport' => 'postMessage',
)
);
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'logo_upload',
array(
'label' => __('Logo Upload'),
'section' => 'title_tagline',
'settings' => 'logo_upload'
)
)
);
//-----------------------Theme Style Section -----------------------//
// Add Theme Styles section
$wp_customize->add_section(
'theme-style',
array(
'title' => __('Theme Colors'),
'description' => __('Note: home page section colors are controlled individually via the page editor.'),
'priority' => 21,
)