-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
536 lines (474 loc) · 15.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
<?php
/**
* Billie functions and definitions
*
* @package Billie
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 640; /* pixels */
}
if ( ! function_exists( 'billie_setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function billie_setup() {
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'woocommerce' );
add_theme_support( 'jetpack-testimonial' );
add_theme_support( 'jetpack-portfolio' );
add_theme_support( 'responsive-embeds' );
add_editor_style();
add_theme_support(
'custom-logo',
array(
'height' => 200,
'width' => 200,
'flex-height' => true,
'flex-width' => true,
)
);
add_theme_support( 'post-thumbnails' );
add_image_size( 'billie-featured-posts-thumb', 360, 300 );
add_theme_support( 'title-tag' );
register_nav_menus(
array(
'header' => __( 'Primary Menu', 'billie' ),
'social' => __( 'Social Menu', 'billie' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) );
add_theme_support( 'customize-selective-refresh-widgets' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'align-wide' );
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Billie blue', 'billie' ),
'slug' => 'billie-blue',
'color' => '#9cc9c7 ',
),
)
);
add_theme_support(
'starter-content',
array(
'posts' => array(
'about',
'contact',
),
'nav_menus' => array(
'social' => array(
'name' => __( 'Social Menu', 'billie' ),
'items' => array(
'link_facebook',
'link_twitter',
'link_instagram',
'link_email',
),
),
'header' => array(
'name' => __( 'Primary Menu', 'billie' ),
'items' => array(
'page_about',
'page_contact',
),
),
),
'options' => array(
'show_on_front' => 'posts',
),
'widgets' => array(
'sidebar-1' => array(
'search',
'recent-posts',
'recent-comments',
),
'sidebar-3' => array(
'search',
'recent-posts',
'recent-comments',
),
'sidebar-4' => array(
'search',
'recent-posts',
'recent-comments',
),
// This sidebar is visible in the footer.
'sidebar-2' => array(
'text_about',
'text_business_info',
),
),
)
);
}
} // End if().
add_action( 'after_setup_theme', 'billie_setup' );
if ( ! get_theme_mod( 'billie_hide_title' ) ) {
/**
* Unless the option is hidden in the customizer, display the site title (with link) in the primary menu.
*/
function billie_menu_title( $items, $args ) {
if ( $args->theme_location == 'header' ) {
$new_item = array( '<li class="toptitle"><a href="' . esc_url( home_url( '/' ) ) . '" rel="home">' . esc_html( get_bloginfo( 'name' ) ) . '</a></li>' );
$items = preg_replace( '/<\/li>\s<li/', '</li>,<li', $items );
$array_items = explode( ',', $items );
array_splice( $array_items, 0, 0, $new_item ); // splice in at position 1.
$items = implode( '', $array_items );
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'billie_menu_title', 10, 2 );
}
/**
* Register widget areas.
*
* @link https://codex.wordpress.org/Function_Reference/register_sidebar
*/
function billie_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar for posts and pages', 'billie' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( 'Front page Sidebar', 'billie' ),
'id' => 'sidebar-3',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( 'Sidebar for archives and search results', 'billie' ),
'id' => 'sidebar-4',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( 'Footer widget area', 'billie' ),
'id' => 'sidebar-2',
'description' => '',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => __( 'Footer copyright area', 'billie' ),
'id' => 'sidebar-copyright',
'description' => __( 'Place a text widget in this area and add your copyright text', 'billie' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
)
);
}
add_action( 'widgets_init', 'billie_widgets_init' );
if ( ! function_exists( 'billie_fonts_url' ) ) {
/**
* Custom fonts.
*/
function billie_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'billie' ) ) {
$fonts[] = 'Montserrat';
}
/* translators: To add an additional character subset specific to your language, translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language. */
$subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'billie' );
if ( 'cyrillic' == $subset ) {
$subsets .= ',cyrillic,cyrillic-ext';
} elseif ( 'greek' == $subset ) {
$subsets .= ',greek,greek-ext';
} elseif ( 'devanagari' == $subset ) {
$subsets .= ',devanagari';
} elseif ( 'vietnamese' == $subset ) {
$subsets .= ',vietnamese';
}
if ( $fonts ) {
$fonts_url = add_query_arg(
array(
'family' => rawurlencode( implode( '|', $fonts ) ),
'subset' => rawurlencode( $subsets ),
'display' => urlencode( 'fallback' ),
),
'//fonts.googleapis.com/css'
);
}
return $fonts_url;
}
}
/**
* Enqueue scripts and styles.
*/
function billie_scripts() {
wp_enqueue_style( 'billie-style', get_stylesheet_uri() );
wp_style_add_data( 'billie-style', 'rtl', 'replace' );
wp_enqueue_style( 'billie-fonts', billie_fonts_url(), array(), null );
wp_enqueue_style( 'open-sans' );
wp_enqueue_script( 'billie-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
wp_enqueue_script( 'billie-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20120206', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'billie_scripts' );
/**
* Add styles and fonts for the new block editor.
*/
function billie_gutenberg_assets() {
wp_enqueue_style( 'open-sans' );
wp_enqueue_style( 'billie-fonts-gutenberg', billie_fonts_url(), array(), null );
wp_enqueue_style( 'billie-gutenberg', get_theme_file_uri( 'gutenberg-editor.css' ), false );
wp_enqueue_script( 'billie-block-styles-script', get_theme_file_uri( '/js/block-styles.js' ), array( 'wp-blocks', 'wp-i18n' ) );
wp_set_script_translations( 'billie-block-styles-script', 'billie' );
}
add_action( 'enqueue_block_editor_assets', 'billie_gutenberg_assets' );
/**
* Add custom block styles.
*/
function billie_block_styles() {
wp_enqueue_style( 'billie-block-styles', get_theme_file_uri( '/inc/custom-block-styles.css' ), false );
}
add_action( 'enqueue_block_assets', 'billie_block_styles' );
/**
* Custom header for this theme.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
add_filter( 'the_title', 'billie_post_title' );
/**
* Add a title to posts that are missing titles.
*/
function billie_post_title( $title ) {
if ( $title == '' ) {
return __( '(Untitled)', 'billie' );
} else {
return $title;
}
}
/**
* Add a class to the body if there is no sidebar.
*/
function billie_no_sidebars( $classes ) {
if ( is_front_page() && ! is_active_sidebar( 'sidebar-3' ) || is_home() && ! is_active_sidebar( 'sidebar-3' ) ) {
$classes[] = 'no-sidebar';
}
return $classes;
}
add_filter( 'body_class', 'billie_no_sidebars' );
if ( ! function_exists( 'billie_call_to_action' ) ) {
/**
* Call to action in the front page header.
*/
function billie_call_to_action() {
if ( ! get_theme_mod( 'billie_hide_action' ) ) {
if ( get_theme_mod( 'billie_action_text' ) ) {
echo '<div id="action">';
if ( get_theme_mod( 'billie_action_link' ) ) {
echo '<a href="' . esc_url( get_theme_mod( 'billie_action_link' ) ) . '">' . esc_html( get_theme_mod( 'billie_action_text' ) ) . '</a>';
} else {
echo esc_html( get_theme_mod( 'billie_action_text' ) );
}
echo '</div>';
} elseif ( current_user_can( 'edit_theme_options' ) ) {
echo '<div id="action"><a href="' . esc_url( home_url( '/wp-admin/customize.php' ) ) . '">' . esc_html__( 'Click here to setup your Call to Action', 'billie' ) . '</a></div>';
}
}
}
}
/**
* Custom CSS for the different options.
*/
function billie_customize_css() {
echo '<style type="text/css">';
echo '.site-title, .site-description{color:#' . esc_attr( get_header_textcolor() ) . ';} ';
$header_image = get_header_image();
if ( ! empty( $header_image ) ) {
?>
.site-header {
background: <?php echo esc_attr( get_theme_mod( 'billie_header_bgcolor', '#9cc9c7' ) ); ?> url(<?php header_image(); ?>)
<?php echo esc_attr( get_theme_mod( 'billie_header_bgrepeat', 'no-repeat' ) ); ?>
<?php echo esc_attr( get_theme_mod( 'billie_header_bgpos', 'center top' ) ); ?>;
background-size: <?php echo esc_attr( get_theme_mod( 'billie_header_bgsize', 'cover' ) ); ?>;
}
<?php
/* No header image has been chosen, check for background color: */
} else {
if ( get_theme_mod( 'billie_header_bgcolor' ) ) {
echo '.site-header { background:' . esc_attr( get_theme_mod( 'billie_header_bgcolor', '#9cc9c7' ) ) . ';}';
echo '#action:hover, #action:focus{text-shadow:none;}';
}
}
// Call to Action text color.
if ( get_theme_mod( 'billie_action_color' ) ) {
echo '#action, #action a{ color:' . esc_attr( get_theme_mod( 'billie_action_color', '#000000' ) ) . ';}';
}
// Call to Action background color.
if ( get_theme_mod( 'billie_action_bgcolor' ) ) {
echo '#action, #action a{background:#' . esc_attr( get_theme_mod( 'billie_action_bgcolor', 'none' ) ) . ';}';
}
// If avatars are enabled, alter the css.
if ( get_option( 'show_avatars' ) ) {
echo '.comment-metadata {
margin-left: 70px;
display: block;
margin-top:-25px;
}';
}
// Menu colors.
if ( get_theme_mod( 'billie_menu_bgcolor' ) ) {
echo '.main-navigation a, .main-navigation a:hover, .main-navigation a:focus, .main-navigation ul ul a {background:' . esc_attr( get_theme_mod( 'billie_menu_bgcolor' ) ) . ';}';
}
if ( get_theme_mod( 'billie_menu_color', '#000' ) !== '#000' ) {
echo '.main-navigation a, .main-navigation a:hover, .main-navigation a:focus, .main-navigation ul ul a {color:' . esc_attr( get_theme_mod( 'billie_menu_color' ) ) . ';}';
}
echo '</style>' . "\n";
}
add_action( 'wp_head', 'billie_customize_css' );
if ( ! function_exists( 'billie_top_sections' ) ) {
/**
* Top page section for the front page.
*/
function billie_top_sections() {
/*The front page sections should not display on the blog listing page. */
if ( is_front_page() && is_home() || is_page_template( 'templates/sections.php' ) ) {
if ( get_theme_mod( 'billie_top_section1' ) || get_theme_mod( 'billie_top_section2' ) || get_theme_mod( 'billie_top_section3' ) ) {
$args = array(
'post_type' => 'page',
'orderby' => 'post__in',
'post__in' => array(
get_theme_mod( 'billie_top_section1' ),
get_theme_mod( 'billie_top_section2' ),
get_theme_mod( 'billie_top_section3' ),
),
);
$top_section_query = new WP_Query( $args );
if ( $top_section_query->have_posts() ) {
echo '<div class="frontpage-top">';
while ( $top_section_query->have_posts() ) :
$top_section_query->the_post();
get_template_part( 'content', 'page' );
endwhile;
wp_reset_postdata();
echo '</div>';
}
}
}
}
}
if ( ! function_exists( 'billie_bottom_sections' ) ) {
/**
* Bottom page section for the front page.
*/
function billie_bottom_sections() {
/*The front page sections should not display on the blog listing page*/
if ( is_front_page() && is_home() || is_page_template( 'templates/sections.php' ) ) {
if ( get_theme_mod( 'billie_bottom_section1' ) || get_theme_mod( 'billie_bottom_section2' ) || get_theme_mod( 'billie_bottom_section3' ) ) {
$bottomargs = array(
'post_type' => 'page',
'orderby' => 'post__in',
'post__in' => array(
get_theme_mod( 'billie_bottom_section1' ),
get_theme_mod( 'billie_bottom_section2' ),
get_theme_mod( 'billie_bottom_section3' ),
),
);
$bottom_section_query = new WP_Query( $bottomargs );
if ( $bottom_section_query->have_posts() ) {
echo '<div class="frontpage-bottom">';
while ( $bottom_section_query->have_posts() ) :
$bottom_section_query->the_post();
get_template_part( 'content', 'page' );
endwhile;
wp_reset_postdata();
echo '</div>';
}
}
}
}
}
if ( ! function_exists( 'billie_featured_sections' ) ) {
/**
* Jetpack Featured posts.
*/
function billie_featured_sections() {
if ( billie_has_featured_posts( 1 ) ) {
global $post;
echo '<section class="featured-wrap">';
$featured_posts = billie_get_featured_posts();
foreach ( (array) $featured_posts as $order => $post ) :
setup_postdata( $post );
echo '<div class="featured-post">';
if ( has_post_thumbnail() ) {
$background = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'billie-featured-posts-thumb' );
echo '<div class="featured-inner" style="background: url(' . esc_url( $background[0] ) . ') center center no-repeat;">';
} else {
echo '<div class="featured-inner" style="background: ' . esc_attr( get_theme_mod( 'billie_header_bgcolor', '#9cc9c7' ) ) . ';">';
}
echo '<div class="post-header">';
the_title( sprintf( '<h2><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
echo '</div>
<span class="featured-text">';
echo esc_html( get_theme_mod( 'billie_featured_headline', esc_html__( 'Featured', 'billie' ) ) );
echo '<span class="tag-list">';
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
$time_string = sprintf(
$time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
);
echo $time_string;
echo '</span>
</span>
</div></div>';
endforeach;
wp_reset_postdata();
echo '</section>';
}
}
} // End if().