-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
199 lines (166 loc) · 6.75 KB
/
functions.php
File metadata and controls
199 lines (166 loc) · 6.75 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
<?php
/**
* ExtraChill Theme Bootstrap
*
* WordPress multisite theme serving all 10 sites with direct require_once loading pattern.
* Uses centralized template routing (template-router.php) and conditional asset loading (assets.php).
*
* @package ExtraChill
* @since 1.0.0
*/
add_theme_support( 'responsive-embeds' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'align-wide' );
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
if ( ! function_exists( 'extrachill_setup' ) ) :
function extrachill_setup() {
load_theme_textdomain( 'extrachill', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'woocommerce' );
add_theme_support( 'title-tag' );
add_post_type_support( 'page', 'excerpt' );
add_theme_support( 'editor-styles' );
add_editor_style( 'assets/css/root.css' );
add_editor_style( 'assets/css/editor-style.css' );
add_editor_style( 'assets/css/editor-style-admin.css' );
add_editor_style( 'assets/css/single-post.css' );
add_editor_style( 'assets/css/block-editor.css' );
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'script',
)
);
add_theme_support(
'custom-logo',
array(
'flex-width' => true,
'flex-height' => true,
)
);
}
endif;
add_action( 'after_setup_theme', 'extrachill_setup' );
/**
* Register custom image sizes for gallery and lightbox use.
*
* - gallery: optimized for gallery column display (cropped to consistent aspect ratio)
* - 2048x2048 is intentionally NOT removed — it serves as a useful intermediate
* for lightbox display, avoiding the jump from 1024px (large) to full-size originals.
* - thumbnail is removed because it's unused in the theme.
*/
function extrachill_unregister_image_sizes() {
remove_image_size( 'thumbnail' );
}
add_action( 'init', 'extrachill_unregister_image_sizes', 99 );
function extrachill_register_image_sizes() {
add_image_size( 'gallery', 800, 600, true );
}
add_action( 'after_setup_theme', 'extrachill_register_image_sizes' );
/**
* Fix gallery image sizes attribute for responsive loading.
*
* WordPress defaults the sizes attribute to "(max-width: {width}px) 100vw, {width}px"
* which tells the browser that gallery images need full-viewport-width sources.
* In reality, gallery images display in 2-3 columns at ~300px height, so the browser
* downloads 1024px images when 400-600px would suffice.
*
* Uses the_content filter (late priority) because wp_content_img_tag only receives
* the <img> tag, not the surrounding <figure class="wp-block-image"> wrapper. We
* need the wrapper context to detect gallery images.
*
* @param string $content Post content HTML.
* @return string Modified content with gallery-aware sizes attributes.
*/
function extrachill_gallery_image_sizes( string $content ): string {
if ( strpos( $content, 'wp-block-gallery' ) === false ) {
return $content;
}
// Gallery images display in columns: ~50vw on tablet, ~33vw on desktop.
// On mobile they go full-width. This tells the browser to pick appropriately
// sized sources instead of always downloading the largest available.
$gallery_sizes = '(max-width: 480px) 100vw, (max-width: 768px) 50vw, 33vw';
// Match <figure class="wp-block-image ...">...<img ... sizes="...">...</figure>
// and replace the sizes attribute on images inside gallery figures.
$content = preg_replace_callback(
'/<figure\s[^>]*class="[^"]*wp-block-image[^"]*"[^>]*>.*?<\/figure>/s',
function ( $match ) use ( $gallery_sizes ) {
return preg_replace(
'/sizes="[^"]*"/',
'sizes="' . esc_attr( $gallery_sizes ) . '"',
$match[0]
);
},
$content
);
return $content;
}
add_filter( 'the_content', 'extrachill_gallery_image_sizes', 999 );
define( 'EXTRACHILL_PARENT_DIR', get_template_directory() );
define( 'EXTRACHILL_THEME_VERSION', '2.0.14' );
define( 'EXTRACHILL_INCLUDES_DIR', EXTRACHILL_PARENT_DIR . '/inc' );
require_once EXTRACHILL_INCLUDES_DIR . '/core/templates/post-meta.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/templates/pagination.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/templates/no-results.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/templates/share.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/templates/social-links.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/templates/taxonomy-badges.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/actions.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/assets.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/icons.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/notices.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/rewrite.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/site-title.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/template-router.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/templates/breadcrumbs.php';
require_once EXTRACHILL_INCLUDES_DIR . '/header/header-search.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/custom-taxonomies.php';
require_once EXTRACHILL_INCLUDES_DIR . '/sidebar/recent-posts.php';
require_once EXTRACHILL_INCLUDES_DIR . '/footer/back-to-home-link.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/editor/bandcamp-embeds.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/editor/instagram-embeds.php';
require_once EXTRACHILL_INCLUDES_DIR . '/archives/archive-custom-sorting.php';
require_once EXTRACHILL_INCLUDES_DIR . '/components/filter-bar.php';
require_once EXTRACHILL_INCLUDES_DIR . '/components/filter-bar-defaults.php';
require_once EXTRACHILL_INCLUDES_DIR . '/core/templates/searchform.php';
function extrachill_allow_svg_uploads( $file_types ) {
$file_types['svg'] = 'image/svg+xml';
return $file_types;
}
add_filter( 'upload_mimes', 'extrachill_allow_svg_uploads' );
function extrachill_prevent_admin_styles_on_frontend() {
if ( is_admin() ) {
return;
}
if ( ! is_user_logged_in() || ! is_admin_bar_showing() ) {
wp_dequeue_style( 'admin-bar' );
}
wp_dequeue_style( 'imagify-admin-bar' );
wp_dequeue_style( 'wp-block-library-theme' );
}
add_action( 'wp_enqueue_scripts', 'extrachill_prevent_admin_styles_on_frontend', 100 );
function extrachill_add_sticky_header_class( $classes ) {
if ( apply_filters( 'extrachill_enable_sticky_header', true ) ) {
$classes[] = 'sticky-header';
}
return $classes;
}
add_filter( 'body_class', 'extrachill_add_sticky_header_class' );
function extrachill_dequeue_jquery_frontend() {
if ( is_admin() ) {
return;
}
$should_dequeue = apply_filters( 'extrachill_dequeue_jquery_frontend', true );
if ( ! $should_dequeue ) {
return;
}
wp_dequeue_script( 'jquery' );
wp_deregister_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'extrachill_dequeue_jquery_frontend', 100 );