-
Notifications
You must be signed in to change notification settings - Fork 280
/
functions.php
executable file
·266 lines (215 loc) · 6.62 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
<?php
/**
* Genesis Sample.
*
* This file adds functions to the Genesis Sample Theme.
*
* @package Genesis Sample
* @author StudioPress
* @license GPL-2.0-or-later
* @link https://www.studiopress.com/
*/
// Starts the engine.
require_once get_template_directory() . '/lib/init.php';
// Sets up the Theme.
require_once get_stylesheet_directory() . '/lib/theme-defaults.php';
add_action( 'after_setup_theme', 'genesis_sample_localization_setup' );
/**
* Sets localization (do not remove).
*
* @since 1.0.0
*/
function genesis_sample_localization_setup() {
load_child_theme_textdomain( genesis_get_theme_handle(), get_stylesheet_directory() . '/languages' );
}
// Adds helper functions.
require_once get_stylesheet_directory() . '/lib/helper-functions.php';
// Adds image upload and color select to Customizer.
require_once get_stylesheet_directory() . '/lib/customize.php';
// Includes Customizer CSS.
require_once get_stylesheet_directory() . '/lib/output.php';
// Adds WooCommerce support.
require_once get_stylesheet_directory() . '/lib/woocommerce/woocommerce-setup.php';
// Adds the required WooCommerce styles and Customizer CSS.
require_once get_stylesheet_directory() . '/lib/woocommerce/woocommerce-output.php';
// Adds the Genesis Connect WooCommerce notice.
require_once get_stylesheet_directory() . '/lib/woocommerce/woocommerce-notice.php';
add_action( 'after_setup_theme', 'genesis_child_gutenberg_support' );
/**
* Adds Gutenberg opt-in features and styling.
*
* @since 2.7.0
*/
function genesis_child_gutenberg_support() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- using same in all child themes to allow action to be unhooked.
require_once get_stylesheet_directory() . '/lib/gutenberg/init.php';
}
// Registers the responsive menus.
if ( function_exists( 'genesis_register_responsive_menus' ) ) {
genesis_register_responsive_menus( genesis_get_config( 'responsive-menus' ) );
}
add_action( 'wp_enqueue_scripts', 'genesis_sample_enqueue_scripts_styles' );
/**
* Enqueues scripts and styles.
*
* @since 1.0.0
*/
function genesis_sample_enqueue_scripts_styles() {
$appearance = genesis_get_config( 'appearance' );
wp_enqueue_style( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- see https://core.trac.wordpress.org/ticket/49742
genesis_get_theme_handle() . '-fonts',
$appearance['fonts-url'],
[],
null
);
wp_enqueue_style( 'dashicons' );
if ( genesis_is_amp() ) {
wp_enqueue_style(
genesis_get_theme_handle() . '-amp',
get_stylesheet_directory_uri() . '/lib/amp/amp.css',
[ genesis_get_theme_handle() ],
genesis_get_theme_version()
);
}
}
add_filter( 'body_class', 'genesis_sample_body_classes' );
/**
* Add additional classes to the body element.
*
* @since 3.4.1
*
* @param array $classes Classes array.
* @return array $classes Updated class array.
*/
function genesis_sample_body_classes( $classes ) {
if ( ! genesis_is_amp() ) {
// Add 'no-js' class to the body class values.
$classes[] = 'no-js';
}
return $classes;
}
add_action( 'genesis_before', 'genesis_sample_js_nojs_script', 1 );
/**
* Echo the script that changes 'no-js' class to 'js'.
*
* @since 3.4.1
*/
function genesis_sample_js_nojs_script() {
if ( genesis_is_amp() ) {
return;
}
?>
<script>
//<![CDATA[
(function(){
var c = document.body.classList;
c.remove( 'no-js' );
c.add( 'js' );
})();
//]]>
</script>
<?php
}
add_filter( 'wp_resource_hints', 'genesis_sample_resource_hints', 10, 2 );
/**
* Add preconnect for Google Fonts.
*
* @since 3.4.1
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array URLs to print for resource hints.
*/
function genesis_sample_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( genesis_get_theme_handle() . '-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = [
'href' => 'https://fonts.gstatic.com',
'crossorigin',
];
}
return $urls;
}
add_action( 'after_setup_theme', 'genesis_sample_theme_support', 9 );
/**
* Add desired theme supports.
*
* See config file at `config/theme-supports.php`.
*
* @since 3.0.0
*/
function genesis_sample_theme_support() {
$theme_supports = genesis_get_config( 'theme-supports' );
foreach ( $theme_supports as $feature => $args ) {
add_theme_support( $feature, $args );
}
}
add_action( 'after_setup_theme', 'genesis_sample_post_type_support', 9 );
/**
* Add desired post type supports.
*
* See config file at `config/post-type-supports.php`.
*
* @since 3.0.0
*/
function genesis_sample_post_type_support() {
$post_type_supports = genesis_get_config( 'post-type-supports' );
foreach ( $post_type_supports as $post_type => $args ) {
add_post_type_support( $post_type, $args );
}
}
// Adds image sizes.
add_image_size( 'sidebar-featured', 75, 75, true );
add_image_size( 'genesis-singular-images', 702, 526, true );
// Removes header right widget area.
unregister_sidebar( 'header-right' );
// Removes secondary sidebar.
unregister_sidebar( 'sidebar-alt' );
// Removes site layouts.
genesis_unregister_layout( 'content-sidebar-sidebar' );
genesis_unregister_layout( 'sidebar-content-sidebar' );
genesis_unregister_layout( 'sidebar-sidebar-content' );
// Repositions primary navigation menu.
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_header', 'genesis_do_nav', 12 );
// Repositions the secondary navigation menu.
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_footer', 'genesis_do_subnav', 10 );
add_filter( 'wp_nav_menu_args', 'genesis_sample_secondary_menu_args' );
/**
* Reduces secondary navigation menu to one level depth.
*
* @since 2.2.3
*
* @param array $args Original menu options.
* @return array Menu options with depth set to 1.
*/
function genesis_sample_secondary_menu_args( $args ) {
if ( 'secondary' === $args['theme_location'] ) {
$args['depth'] = 1;
}
return $args;
}
add_filter( 'genesis_author_box_gravatar_size', 'genesis_sample_author_box_gravatar' );
/**
* Modifies size of the Gravatar in the author box.
*
* @since 2.2.3
*
* @param int $size Original icon size.
* @return int Modified icon size.
*/
function genesis_sample_author_box_gravatar( $size ) {
return 90;
}
add_filter( 'genesis_comment_list_args', 'genesis_sample_comments_gravatar' );
/**
* Modifies size of the Gravatar in the entry comments.
*
* @since 2.2.3
*
* @param array $args Gravatar settings.
* @return array Gravatar settings with modified size.
*/
function genesis_sample_comments_gravatar( $args ) {
$args['avatar_size'] = 60;
return $args;
}