generated from lightspeedwp/block-theme-scaffold
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
178 lines (159 loc) · 5.1 KB
/
functions.php
File metadata and controls
178 lines (159 loc) · 5.1 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 Medical Academic
*
* @package ma-theme
* @since 1.0.0
*/
// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Theme version.
*/
define( 'MA_THEME_VERSION', '1.0.0' );
/**
* Theme setup.
*/
function ma_theme_setup() {
// Make theme available for translation.
load_theme_textdomain( 'ma-theme', 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( 'ma-theme_content_width', 720 );
}
add_action( 'after_setup_theme', 'ma_theme_setup' );
/**
* Enqueue theme assets.
*/
function ma_theme_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(
'ma-theme-style',
get_theme_file_uri( 'build/css/style.css' ),
$asset['dependencies'] ?? array(),
$asset['version'] ?? MA_THEME_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(
'ma-theme-script',
get_theme_file_uri( 'build/js/theme.js' ),
$js_asset['dependencies'] ?? array(),
$js_asset['version'] ?? MA_THEME_VERSION,
true
);
// Set script translations.
wp_set_script_translations(
'ma-theme-script',
'ma-theme',
get_theme_file_path( 'languages' )
);
}
}
add_action( 'wp_enqueue_scripts', 'ma_theme_enqueue_assets' );
/**
* Enqueue editor assets.
*/
function ma_theme_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(
'ma-theme-editor-style',
get_theme_file_uri( 'build/css/editor-style.css' ),
array_merge( array( 'wp-block-editor' ), $editor_asset['dependencies'] ?? array() ),
$editor_asset['version'] ?? MA_THEME_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(
'ma-theme-editor-script',
get_theme_file_uri( 'build/js/editor.js' ),
$editor_js_asset['dependencies'] ?? array(),
$editor_js_asset['version'] ?? MA_THEME_VERSION,
true
);
// Set script translations for editor.
wp_set_script_translations(
'ma-theme-editor-script',
'ma-theme',
get_theme_file_path( 'languages' )
);
}
}
add_action( 'enqueue_block_editor_assets', 'ma_theme_enqueue_editor_assets' );
/**
* Register block pattern categories.
*/
function ma_theme_register_pattern_categories() {
$categories = array(
'ma-theme-hero' => array( 'label' => __( 'Medical Academic Hero', 'ma-theme' ) ),
'ma-theme-about' => array( 'label' => __( 'Medical Academic About', 'ma-theme' ) ),
'ma-theme-contact' => array( 'label' => __( 'Medical Academic Contact', 'ma-theme' ) ),
'ma-theme-cta' => array( 'label' => __( 'Medical Academic Call to Action', 'ma-theme' ) ),
'ma-theme-gallery' => array( 'label' => __( 'Medical Academic Gallery', 'ma-theme' ) ),
'ma-theme-team' => array( 'label' => __( 'Medical Academic Team', 'ma-theme' ) ),
);
foreach ( $categories as $slug => $args ) {
register_block_pattern_category( $slug, $args );
}
}
add_action( 'init', 'ma_theme_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 ma_theme_add_image_sizes() {
add_image_size( 'ma-theme-featured', 1200, 630, true );
add_image_size( 'ma-theme-thumbnail', 150, 150, true );
add_image_size( 'ma-theme-gallery', 800, 600, true );
}
add_action( 'after_setup_theme', 'ma_theme_add_image_sizes' );
/**
* Modify excerpt length.
*/
function ma_theme_excerpt_length( $length ) {
return 55;
}
add_filter( 'excerpt_length', 'ma_theme_excerpt_length' );
/**
* Modify excerpt more.
*/
function ma_theme_excerpt_more( $more ) {
return '...';
}
add_filter( 'excerpt_more', 'ma_theme_excerpt_more' );