-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
178 lines (159 loc) · 5.65 KB
/
Copy pathfunctions.php
File metadata and controls
178 lines (159 loc) · 5.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
<?php
/**
* Functions and definitions for {{theme_name}}
*
* @package {{theme_slug}}
* @since {{version}}
*/
// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Theme version.
*/
define( '{{theme_slug|upper}}_VERSION', '{{version}}' );
/**
* Theme setup.
*/
function {{theme_slug|snakeCase}}_setup() {
// Make theme available for translation.
load_theme_textdomain( '{{theme_slug}}', get_template_directory() . '/languages' );
// Add theme support for various features.
add_theme_support( 'wp-block-styles' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'editor-styles' );
add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'gallery', 'caption' ) );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'align-wide' );
add_theme_support( 'custom-logo' );
// Add editor styles.
add_editor_style( 'build/css/editor-style.css' );
// Set content width.
$GLOBALS['content_width'] = apply_filters( '{{theme_slug}}_content_width', {{content_width_num}} );
}
add_action( 'after_setup_theme', '{{theme_slug|snakeCase}}_setup' );
/**
* Enqueue theme assets.
*/
function {{theme_slug|snakeCase}}_enqueue_assets() {
// Main stylesheet.
$asset_file = get_theme_file_path( 'build/css/style.asset.php' );
if ( file_exists( $asset_file ) ) {
$asset = include $asset_file;
wp_enqueue_style(
'{{theme_slug}}-style',
get_theme_file_uri( 'build/css/style.css' ),
$asset['dependencies'] ?? array(),
$asset['version'] ?? {{theme_slug|upper}}_VERSION
);
}
// Main JavaScript.
$js_asset_file = get_theme_file_path( 'build/js/theme.asset.php' );
if ( file_exists( $js_asset_file ) ) {
$js_asset = include $js_asset_file;
wp_enqueue_script(
'{{theme_slug}}-script',
get_theme_file_uri( 'build/js/theme.js' ),
$js_asset['dependencies'] ?? array(),
$js_asset['version'] ?? {{theme_slug|upper}}_VERSION,
true
);
// Set script translations.
wp_set_script_translations(
'{{theme_slug}}-script',
'{{theme_slug}}',
get_theme_file_path( 'languages' )
);
}
}
add_action( 'wp_enqueue_scripts', '{{theme_slug|snakeCase}}_enqueue_assets' );
/**
* Enqueue editor assets.
*/
function {{theme_slug|snakeCase}}_enqueue_editor_assets() {
$editor_asset_file = get_theme_file_path( 'build/css/editor-style.asset.php' );
if ( file_exists( $editor_asset_file ) ) {
$editor_asset = include $editor_asset_file;
wp_enqueue_style(
'{{theme_slug}}-editor-style',
get_theme_file_uri( 'build/css/editor-style.css' ),
$editor_asset['dependencies'] ?? array(),
$editor_asset['version'] ?? {{theme_slug|upper}}_VERSION
);
}
// Enqueue editor JavaScript.
$editor_js_asset_file = get_theme_file_path( 'build/js/editor.asset.php' );
if ( file_exists( $editor_js_asset_file ) ) {
$editor_js_asset = include $editor_js_asset_file;
wp_enqueue_script(
'{{theme_slug}}-editor-script',
get_theme_file_uri( 'build/js/editor.js' ),
$editor_js_asset['dependencies'] ?? array(),
$editor_js_asset['version'] ?? {{theme_slug|upper}}_VERSION,
true
);
// Set script translations for editor.
wp_set_script_translations(
'{{theme_slug}}-editor-script',
'{{theme_slug}}',
get_theme_file_path( 'languages' )
);
}
}
add_action( 'enqueue_block_editor_assets', '{{theme_slug|snakeCase}}_enqueue_editor_assets' );
/**
* Register block pattern categories.
*/
function {{theme_slug|snakeCase}}_register_pattern_categories() {
$categories = array(
'{{theme_slug}}-hero' => array( 'label' => __( '{{theme_name}} Hero', '{{theme_slug}}' ) ),
'{{theme_slug}}-about' => array( 'label' => __( '{{theme_name}} About', '{{theme_slug}}' ) ),
'{{theme_slug}}-contact' => array( 'label' => __( '{{theme_name}} Contact', '{{theme_slug}}' ) ),
'{{theme_slug}}-cta' => array( 'label' => __( '{{theme_name}} Call to Action', '{{theme_slug}}' ) ),
'{{theme_slug}}-gallery' => array( 'label' => __( '{{theme_name}} Gallery', '{{theme_slug}}' ) ),
'{{theme_slug}}-team' => array( 'label' => __( '{{theme_name}} Team', '{{theme_slug}}' ) ),
);
foreach ( $categories as $slug => $args ) {
register_block_pattern_category( $slug, $args );
}
}
add_action( 'init', '{{theme_slug|snakeCase}}_register_pattern_categories' );
/**
* Load theme includes.
*/
$theme_includes = array(
'inc/block-patterns.php',
'inc/block-styles.php',
'inc/template-functions.php',
);
foreach ( $theme_includes as $file ) {
$filepath = get_theme_file_path( $file );
if ( file_exists( $filepath ) ) {
require_once $filepath;
}
}
/**
* Add custom image sizes.
*/
function {{theme_slug|snakeCase}}_add_image_sizes() {
add_image_size( '{{theme_slug}}-featured', {{featured_image_width}}, {{featured_image_height}}, true );
add_image_size( '{{theme_slug}}-thumbnail', {{thumbnail_width}}, {{thumbnail_height}}, true );
add_image_size( '{{theme_slug}}-gallery', {{gallery_image_width}}, {{gallery_image_height}}, true );
}
add_action( 'after_setup_theme', '{{theme_slug|snakeCase}}_add_image_sizes' );
/**
* Modify excerpt length.
*/
function {{theme_slug|snakeCase}}_excerpt_length( $length ) {
return {{excerpt_length}};
}
add_filter( 'excerpt_length', '{{theme_slug|snakeCase}}_excerpt_length' );
/**
* Modify excerpt more.
*/
function {{theme_slug|snakeCase}}_excerpt_more( $more ) {
return '{{excerpt_more}}';
}
add_filter( 'excerpt_more', '{{theme_slug|snakeCase}}_excerpt_more' );