-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
207 lines (188 loc) · 6.67 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
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
<?php
require 'inc/constants.php';
add_action( 'after_setup_theme', 'kagami_setup' );
function kagami_setup() {
load_theme_textdomain( 'kagami', get_template_directory() . '/languages' );
register_nav_menus(
array(
'top' => __( 'Top Menu', 'kagami' ),
'social' => __( 'Social Links Menu', 'kagami' ),
)
);
add_theme_support(
'custom-logo',
array(
'height' => 50,
'width' => 300,
'flex-width' => true,
)
);
// add_theme_support( 'custom-background' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'title-tag' );
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'script',
'style',
)
);
load_theme_textdomain( 'kagami' );
}
//
require get_template_directory() . '/inc/template-tags.php';
require get_template_directory() . '/inc/class-kagami-walker-comment.php';
function kagami_customize_register( $wp_customize ) {
// 1. Colors Section
// 1.1 Primary Color
$wp_customize->add_setting( 'primary_color', array(
'default' => '#6b7dd6',
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_hex_color',
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'primary_color', array(
'label' => __( 'Primary Color', 'kagami' ),
'section' => 'colors',
)));
// 1.2 Text Color
$wp_customize->add_setting( 'text_color', array(
'default' => '#333',
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_hex_color',
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'text_color', array(
'label' => __( 'Text Color', 'kagami' ),
'section' => 'colors',
)));
// 2. Kagami Section
$wp_customize->add_section( 'kagami', array(
'title' => __( 'Kagami Settings', 'kagami' ),
'description' => __( 'Kagami Settings', 'kagami' ),
'panel' => '', // Not typically needed.
'priority' => 160,
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
));
$wp_customize->add_setting( 'use_jsdelivr', array(
'default' => false,
'type' => 'theme_mod',
));
$wp_customize->add_control( 'use_jsdelivr', array(
'label' => __( 'Use jsdelivr', 'kagami' ),
'type' => 'checkbox',
'section' => 'kagami',
));
// 3. Footer Section
$wp_customize->add_section( 'footer', array(
'title' => __( 'Footer', 'kagami' ),
'description' => __( 'Footer', 'kagami' ),
'panel' => '', // Not typically needed.
'priority' => 161,
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
));
// 3.1 Footer Gradient Start Color
$wp_customize->add_setting( 'footer_gradient_start_color', array(
'default' => '#6b7dd6',
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_hex_color',
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_gradient_start_color', array(
'label' => __( 'Footer Color Start', 'kagami' ),
'section' => 'footer',
)));
// 3.2 Footer Gradient End Color
$wp_customize->add_setting( 'footer_gradient_end_color', array(
'default' => '#001689',
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_hex_color',
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_gradient_end_color', array(
'label' => __( 'Footer Color End', 'kagami' ),
'section' => 'footer',
)));
// 3.3 Footer Slogan
$wp_customize->add_setting( 'footer_slogan', array(
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control( 'footer_slogan', array(
'label' => __( 'Footer Slogan', 'kagami' ),
'type' => 'text',
'section' => 'footer',
));
// 3.4 ICP Number
$wp_customize->add_setting( 'icp_number', array(
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control( 'icp_number', array(
'label' => __( 'ICP Number', 'kagami' ),
'type' => 'text',
'section' => 'footer',
));
// 3.5 Footer Extra
$wp_customize->add_setting( 'footer_extra', array(
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control( 'footer_extra', array(
'label' => __( 'Extra Content', 'kagami' ),
'type' => 'text',
'section' => 'footer',
));
}
add_action('customize_register', 'kagami_customize_register');
add_action( 'wp_enqueue_scripts', 'kagami_scripts' );
function kagami_scripts() {
$use_jsdelivr = get_theme_mod('use_jsdelivr', false);
$variables_version = md5( filemtime( get_theme_file_path( '/assets/css/variables.css.php' ) ) );
$custom_style_version = md5( filemtime( get_theme_file_path( '/assets/css/custom.css' ) ) );
if ( $use_jsdelivr ) {
$style_url = 'https://cdn.jsdelivr.net/gh/jinkanhq/kagami@v' . KAGAMI_VERSION . '/assets/css/style.css';
} else {
$style_url = get_theme_file_uri( '/assets/css/style.css' );
}
wp_enqueue_style( 'kagami-variables', admin_url( 'admin-ajax.php' ).'?action=dynamic_css', array(), $variables_version );
wp_enqueue_style( 'kagami-style', $style_url );
wp_enqueue_style( 'kagami-custom', get_theme_file_uri( '/assets/css/custom.css' ), array(), $custom_style_version );
}
add_filter( 'excerpt_length', 'kagami_excerpt_length' );
function kagami_excerpt_length( $length ) {
return 70;
}
add_filter( 'excerpt_more', 'kagami_excerpt_more' );
function kagami_excerpt_more( $more ) {
return "...";
}
add_filter( 'comment_excerpt_length', 'kagami_comment_excerpt_length' );
function kagami_comment_excerpt_length( $length ) {
return 70;
}
add_action( 'wp_ajax_dynamic_css', 'kagami_dynamic_css' );
add_action( 'wp_ajax_nopriv_dynamic_css', 'kagami_dynamic_css' );
function kagami_dynamic_css() {
require get_theme_file_path( '/assets/css/variables.css.php' );
exit;
}
add_filter( 'get_the_archive_title', 'kagami_archive_title' );
function kagami_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = get_the_author();
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
?>