-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
104 lines (91 loc) · 3.27 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
<?php
/**
* Functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @since 0.1
*/
// Shortcodes.
require_once get_template_directory() . '/inc/shortcodes.php';
require_once get_template_directory() . '/inc/customizer.php';
/**
* Register and enqueue frontend scripts and styles
*/
function emma_enqueue_frontend() {
$theme_version = wp_get_theme( get_template() )->get( 'Version' );
$stylesheet = get_template_directory_uri() . '/style.css';
wp_enqueue_style( 'emma', $stylesheet, null, $theme_version );
$flyout_menu_js = get_template_directory_uri() . '/flyout-menu.js';
wp_enqueue_script( 'emma-flyout-menu', $flyout_menu_js, null, $theme_version );
}
add_action( 'wp_enqueue_scripts', 'emma_enqueue_frontend' );
/**
* Enqueue backend scripts for stuff that should always get loaded
*/
function emma_enqueue_editor() {
$theme_version = wp_get_theme( get_template() )->get( 'Version' );
$frontend_stylesheet = get_template_directory_uri() . '/style.css';
wp_enqueue_style( 'emma', $frontend_stylesheet, null, $theme_version );
}
add_action( 'enqueue_block_editor_assets', 'emma_enqueue_editor' );
/**
* Iterate through color palette defined in theme.json and output additional styles for theme
*/
function emma_global_styles_supplemental_colors() {
$global_styles = wp_get_global_settings();
$color_palette = $global_styles['color']['palette']['theme'];
$supplemental_css = "";
foreach( $color_palette as $color ) {
$slug = $color['slug'];
$supplemental_css .= ".has-$slug-background-color{--bg-color:var(--wp--preset--color--$slug) !important}";
}
wp_add_inline_style( 'global-styles', $supplemental_css );
}
add_action( 'wp_enqueue_scripts', 'emma_global_styles_supplemental_colors', 100 );
/**
* Look for menu breakpoint in theme.json and, if it exists, output appropriate CSS
*/
function emma_global_styles_menu_breakpoint() {
$global_styles = wp_get_global_settings();
$menu_breakpoint = $global_styles['custom']['menuBreakpoint'];
ob_start();
?>
.wp-block-navigation .flyout-menu-opener:where( :not( .show-on-desktop ) ) {
display: none;
}
@media screen and ( max-width: calc( <?= $menu_breakpoint ?> - 1px ) ) {
.wp-block-navigation > .wp-block-navigation-item:where( :not( .show-on-mobile ):not( .flyout-menu-opener ) ) {
display: none;
}
.wp-block-navigation .flyout-menu-opener {
display: block;
}
}
<?php
$supplemental_css = ob_get_clean();
wp_add_inline_style( 'global-styles', $supplemental_css );
}
add_action( 'wp_enqueue_scripts', 'emma_global_styles_menu_breakpoint', 100 );
/**
* Prevents posts set to noindex via Yoast SEO plugin from appearing in site search
*/
function emma_remove_noindex_from_wp_search( $query ) {
if ( $query->is_search && ! is_admin() ) {
$query->set( 'meta_query', array(
'relation' => 'OR',
array (
'key' => '_yoast_wpseo_meta-robots-noindex',
'value' => '1',
'compare' => '!='
),
array(
'key' => '_yoast_wpseo_meta-robots-noindex',
'compare' => 'NOT EXISTS',
)
)
);
}
return $query;
}
add_filter( 'pre_get_posts', 'emma_remove_noindex_from_wp_search' );