-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
330 lines (276 loc) · 7.65 KB
/
Copy pathfunctions.php
File metadata and controls
330 lines (276 loc) · 7.65 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
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
<?php
/**
* Theme setup.
*/
function embepiercing_setup() {
add_theme_support( 'title-tag' );
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'embepiercing' ),
)
);
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
add_theme_support( 'custom-logo' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'align-wide' );
add_theme_support( 'wp-block-styles' );
}
add_action( 'after_setup_theme', 'embepiercing_setup' );
/**
* Enqueue theme assets.
*/
function embepiercing_enqueue_scripts() {
wp_enqueue_style( 'embepiercing', embepiercing_asset( 'css/app.css' ), array(), '1.626' );
wp_enqueue_style( 'fonts', embepiercing_asset( 'css/typography.css' ), array(), '1.626' );
if (is_front_page()) {
wp_enqueue_script( 'home', embepiercing_asset( 'js/home.js' ), array(), '1.626' );
}
wp_enqueue_script( 'embepiercing', embepiercing_asset( 'js/app.js' ), array(), '1.626' );
if (is_post_type_archive('faq')) {
wp_enqueue_script( 'faq', embepiercing_asset( 'js/faq.js' ), array(), '1.626' );
}
}
add_action( 'wp_enqueue_scripts', 'embepiercing_enqueue_scripts' );
add_theme_support('category-thumbnails');
add_theme_support( 'post-thumbnails' );
/**
* Defer the reCAPTCHA script until after the page loads
*
* @link https://wpforms.com/developers/how-to-defer-the-recaptcha-script/
*/
function defer_recaptcha_scripts( $tag, $handle ) {
if ( 'google-recaptcha' === $handle ) {
return str_replace( ' src', ' defer="defer" src', $tag );
}
return $tag;
}
add_filter( 'script_loader_tag', 'defer_recaptcha_scripts', 10, 2 );
/**
* Get asset path.
*
* @param string $path Path to asset.
*
* @return string
*/
function embepiercing_asset( $path ) {
if ( wp_get_environment_type() === 'production' ) {
return get_stylesheet_directory_uri() . '/' . $path;
}
return add_query_arg( 'time', time(), get_stylesheet_directory_uri() . '/' . $path );
}
function my_login_logo_one() {
$custom_logo_id = get_theme_mod( 'custom_logo' );
$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
?>
<style type="text/css">
body.login div#login h1 a {
background-image: url(<?php echo $image[0]; ?>);
width: 100%;
height: 100%;
background-size: contain;
padding-bottom: 30px;
}
</style>
<?php
}
add_action( 'login_enqueue_scripts', 'my_login_logo_one' );
/* UTILITIES */
add_filter( 'generate_google_font_display', function() {
return 'swap';
} );
add_filter( 'get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>' ;
} elseif ( is_tax() ) { //for custom post types
$title = sprintf( __( '%1$s' ), single_term_title( '', false ) );
} elseif (is_post_type_archive()) {
$title = post_type_archive_title( '', false );
}
return $title;
});
// add_filter( 'get_the_title', function ($title) {
// if ( is_category() ) {
// $title = single_cat_title( '', false );
// } elseif ( is_tag() ) {
// $title = single_tag_title( '', false );
// } elseif ( is_author() ) {
// $title = '<span class="vcard">' . get_the_author() . '</span>' ;
// } elseif ( is_tax() ) { //for custom post types
// $title = sprintf( __( '%1$s' ), single_term_title( '', false ) );
// } elseif (is_post_type_archive()) {
// $title = post_type_archive_title( '', false );
// }
// return $title;
// });
function header_copyright()
{
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
$output = "";
if ($copyright_dates) {
$copyright = "© " . $copyright_dates[0]->lastdate;
// if ($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
// $copyright .= "-" . $copyright_dates[0]->lastdate;
// }
$output = $copyright;
}
return $output;
}
/**
* Adds option 'li_class' to 'wp_nav_menu'.
*
* @param string $classes String of classes.
* @param mixed $item The curren item.
* @param WP_Term $args Holds the nav menu arguments.
*
* @return array
*/
function embepiercing_nav_menu_add_li_class( $classes, $item, $args, $depth ) {
if ( isset( $args->li_class ) ) {
$classes[] = $args->li_class;
}
if ( isset( $args->{"li_class_$depth"} ) ) {
$classes[] = $args->{"li_class_$depth"};
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'embepiercing_nav_menu_add_li_class', 10, 4 );
/**
* Adds option 'submenu_class' to 'wp_nav_menu'.
*
* @param string $classes String of classes.
* @param mixed $item The curren item.
* @param WP_Term $args Holds the nav menu arguments.
*
* @return array
*/
function embepiercing_nav_menu_add_submenu_class( $classes, $args, $depth ) {
if ( isset( $args->submenu_class ) ) {
$classes[] = $args->submenu_class;
}
if ( isset( $args->{"submenu_class_$depth"} ) ) {
$classes[] = $args->{"submenu_class_$depth"};
}
return $classes;
}
add_filter( 'nav_menu_submenu_css_class', 'embepiercing_nav_menu_add_submenu_class', 10, 3 );
function add_img_size($content) {
$pattern = '/<img [^>]*?src="(https?:\/\/[^"]+?)"[^>]*?>/iu';
preg_match_all($pattern, $content, $imgs);
foreach ( $imgs[0] as $i => $img ) {
if ( false !== strpos( $img, 'width=' ) && false !== strpos( $img, 'height=' ) ) {
continue;
}
$img_url = $imgs[1][$i];
$img_size = @getimagesize( $img_url );
if ( false === $img_size ) {
continue;
}
$replaced_img = str_replace( '<img ', ' <img ' . $img_size[3] . ' ', $imgs[0][$i] );
$content = str_replace( $img, $replaced_img, $content );
}
return $content;
}
/* MENUS */
// Mobile menu
add_filter("wp_nav_menu_objects", "wpdocs_add_menu_parent_class", 11, 3);
function wpdocs_add_menu_parent_class($items)
{
$parents = [];
// Collect menu items with parents.
foreach ($items as $item) {
if ($item->menu_item_parent && $item->menu_item_parent > 0) {
$parents[] = $item->menu_item_parent;
}
}
// Add class.
foreach ($items as $item) {
if (in_array($item->ID, $parents)) {
$item->classes[] = "menu-parent-link"; //here attach the class
}
}
return $items;
}
function prefix_add_button_after_menu_item_children(
$item_output,
$item,
$depth,
$args
) {
if (
in_array("menu-item-has-children", $item->classes) ||
in_array("page_item_has_children", $item->classes)
) {
$item_output = str_replace(
$args->link_after . "</a>",
$args->link_after .
'</a><span class="show-submenu" role="button" tabindex="0" aria-label="show-submenu" aria-expanded="false" aria-pressed="false"></span>',
$item_output
);
}
return $item_output;
}
add_filter(
"walker_nav_menu_start_el",
"prefix_add_button_after_menu_item_children",
10,
4
);
class Has_Child_Walker_Nav_Menu extends Walker_Nav_Menu
{
public function display_element(
$element,
&$children_elements,
$max_depth,
$depth,
$args,
&$output
) {
if (!$element) {
return;
}
$element->has_children = !empty(
$children_elements[$element->{$this->db_fields["id"]}]
);
parent::display_element(
$element,
$children_elements,
$max_depth,
$depth,
$args,
$output
);
}
}
/* excerpt */
function new_excerpt_more( $more ) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
//YOAST
function set_custom_facebook_image_size( $img_size ) { return 'large' ; };
add_filter( 'wpseo_opengraph_image_size' , 'set_custom_facebook_image_size' );
add_filter(' the_content','add_img_size');
add_filter( 'wpseo_metabox_prio' , function() { return 'low' ; } );
add_filter('xmlrpc_enabled', '__return_false' );