-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
139 lines (119 loc) · 4.85 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
<?php
/**
* Storefront automatically loads the core CSS even if using a child theme as it is more efficient
* than @importing it in the child theme style.css file.
*
* Uncomment the line below if you'd like to disable the Storefront Core CSS.
*
* If you don't plan to dequeue the Storefront Core CSS you can remove the subsequent line and as well
* as the sf_child_theme_dequeue_style() function declaration.
*/
//add_action( 'wp_enqueue_scripts', 'sf_child_theme_dequeue_style', 999 );
/**
* Dequeue the Storefront Parent theme core CSS
*/
function sf_child_theme_dequeue_style()
{
wp_dequeue_style('storefront-style');
wp_dequeue_style('storefront-woocommerce-style');
}
/**
* Note: DO NOT! alter or remove the code above this text and only add your custom PHP functions below this text.
*/
//Enqueue fonts and icons for the whole site
add_action( 'wp_enqueue_scripts', 'd4s_enqueue_fonts' );
function d4s_enqueue_fonts() {
wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;700&family=Poppins:wght@300;400;700&display=swap', false);
wp_enqueue_style('fa', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css');
}
// Enqueue scripts , add actions are in header to seperate for landing page and shop, functions are here.
function d4s_enqueue_scripts()
{
wp_enqueue_script('mobile-menu-modal', get_stylesheet_directory_uri() . '/assets/js/mobile-menu-modal.js', array(), true);
wp_enqueue_script('purchase-modal', get_stylesheet_directory_uri() . '/assets/js/purchase-modal.js', array(), true);
wp_enqueue_script('wc-classes', get_stylesheet_directory_uri() . '/assets/js/wc-classes.js', array(), true);
wp_enqueue_script('world-section', get_stylesheet_directory_uri() . '/assets/js/world-section.js', array(), true);
wp_enqueue_script('story-section', get_stylesheet_directory_uri() . '/assets/js/story-section.js', array(), true);
}
// Meant for scripts that need to be deferred to work properly
function d4s_defer_scripts($tag, $handle, $src)
{
$defer = array(
'mobile-menu-modal',
'purchase-modal',
'world-section',
'story-section',
);
if (in_array($handle, $defer)) {
return '<script src="' . $src . '" defer="defer" type="text/javascript"></script>' . "\n";
}
return $tag;
}
// Setup web component to module for Lit to run properly
function d4s_export_scripts($tag, $handle, $src)
{
$export = array(
'wc-classes',
);
if (in_array($handle, $export)) {
return '<script src="' . $src . '" defer="defer" type="module"></script>' . "\n";
}
return $tag;
}
// Dequeue parent scripts that are not needed for landing page
function dequeue_parent_scripts()
{
wp_dequeue_style('storefront-woocommerce-style');
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wc-blocks-vendors-style');
wp_dequeue_style('wc-blocks-style');
wp_dequeue_style('storefront-gutenberg-blocks');
wp_dequeue_style('storefront-style');
wp_dequeue_style('storefront-fonts');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('storefront-icons');
wp_dequeue_style('woocommerce-inline');
wp_dequeue_script('wc-add-to-cart');
wp_dequeue_script('wc-cart-fragments');
wp_dequeue_script('storefront-header-cart');
wp_dequeue_script('storefront-handheld-footer-bar');
wp_dequeue_script('jquery-blockui');
wp_dequeue_script('js-cookie');
wp_dequeue_script('woocommerce');
}
// Console log function in PHP to improve debugging experience
function console_log(...$data)
{
$json = json_encode($data);
add_action('shutdown', function () use ($json) {
echo "<script>console.log({$json})</script>";
});
}
// Declare woocommerce support and setup and basic settings recommend as best practices
add_action('after_setup_theme', 'd4s_theme_config', 0);
function d4s_theme_config()
{
add_theme_support('woocommerce', array(
'thumbnail_image_width' => 255,
'single_image_width' => 255,
'product_grid' => array(
'default_rows' => 10,
'min_rows' => 3,
'max_rows' => 10,
'default_columns' => 3,
'min_columns' => 1,
'max_columns' => 4,
)
));
add_theme_support('wc-product-gallery-zoom');
add_theme_support('wc-product-gallery-lightbox');
add_theme_support('wc-product-gallery-slider');
if (!isset($content_width)) {
$content_width = 600;
}
}
// Setup custom D4S woocommerce configuration by using standard hooks and actions to ensure compatibility with Woocommerce
require_once( 'woocommerce/config/shop-header.php' );
require_once( 'woocommerce/config/shop-archive.php' );
require_once( 'woocommerce/config/shop-single.php' );
require_once( 'woocommerce/config/shop-footer.php' );