-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
281 lines (223 loc) · 6.19 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
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
<?php
/**
* Custom functions for 3cb24 theme
*
* @package 3cb24
*/
/**
* Theme support elements.
*/
function threecb_theme_setup() {
// Support Featured Images.
add_theme_support( 'post-thumbnails' );
// New way of registering page title.
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'threecb_theme_setup' );
/**
* Add theme's CSS file.
*/
function threecb_css() {
wp_enqueue_style( 'threecb-style', get_stylesheet_uri(), array(), '1.0' );
}
add_action( 'wp_enqueue_scripts', 'threecb_css', 1000, 'epkb-mp-frontend-category-layout-css' );
/**
* Remove unwanted CSS files from plugins etc - find the handle in the plugin file and add here.
*/
function remove_unwanted_css() {
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wc-blocks-style' );
wp_dequeue_style( 'global-styles' );
wp_deregister_style( 'classic-theme-styles' );
wp_dequeue_style( 'classic-theme-styles' );
wp_dequeue_style( 'tcb-roster' ); // Roster plugin styles are in main CSS file.
wp_dequeue_style( 'epkb-mp-frontend-category-layout-css' ); // This doesn't work.
}
add_action( 'wp_enqueue_scripts', 'remove_unwanted_css', 100 );
/**
* Disable theme editing.
*/
define( 'DISALLOW_FILE_EDIT', true );
/**
* Remove admin bar.
*/
show_admin_bar( false );
/**
* Remove emoji junk.
*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
/**
* Remove jQuery migrate.
*
* @param array $scripts List of scripts loaded by WP.
*/
function remove_jquery_migrate( &$scripts ) {
if ( ! is_admin() ) {
$scripts->remove( 'jquery' );
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
}
}
add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );
/**
* Add button class to blog pagination links.
*/
function posts_link_attributes() {
return 'class="btn"';
}
add_filter( 'next_posts_link_attributes', 'posts_link_attributes' );
add_filter( 'previous_posts_link_attributes', 'posts_link_attributes' );
/**
* Custom read more function.
*/
function custom_read_more() {
return '... <a class="read-more" href="' . get_permalink( get_the_ID() ) . '">Read more</a>';
}
/**
* Custom excerpt - use echo excerpt(25); to output in theme.
*
* @param integer $limit Length of excerpt passed from get_the template tag.
*/
function excerpt( $limit ) {
return wp_trim_words( get_the_excerpt(), $limit, custom_read_more() );
}
/**
* Register Main Menu.
*/
function register_my_menu() {
register_nav_menu( 'main-menu', __( 'Main Menu' ) );
}
add_action( 'init', 'register_my_menu' );
/**
* Register sidebars.
*/
function sidebar_widgets_init() {
register_sidebar(
array(
'name' => __( 'Blog Sidebar', '3cb24' ),
'id' => 'blog-sidebar',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3>',
'after_title' => '</h3>',
),
);
}
add_action( 'widgets_init', 'sidebar_widgets_init' );
/**
* Load Scripts Properly.
*/
function my_scripts_method() {
// Add toast.
// wp_register_script( 'toast-script', get_template_directory_uri() . '/js/toaster.js', array( 'jquery' ) );.
// wp_enqueue_script( 'toast-script' );.
// Add FCS javascript.
wp_register_script( 'fcs-script', get_template_directory_uri() . '/js/fcs-min.js', array( 'jquery' ), 1.0, true );
wp_enqueue_script( 'fcs-script' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
// Events stuff.
add_action(
'tribe_template_before_include:events/v2/components/events-bar',
function ( $file, $name, $template ) {
echo '<h1 id="eventListingTitle">Events</h1>';
},
10,
3
);
/**
* Add ACF options page.
*/
if ( function_exists( 'acf_add_options_page' ) ) {
acf_add_options_page( 'Global Settings' );
}
/**
* Admin login page CSS.
*/
function my_login_stylesheet() {
wp_enqueue_style( 'custom-login', get_template_directory_uri() . '/style-login.css', 1.0, true );
}
add_action( 'login_enqueue_scripts', 'my_login_stylesheet' );
/**
* Custom admin CSS to remove plugin ads etc.
*/
function register_custom_admin_css() {
wp_enqueue_style( 'custom_admin_css', get_template_directory_uri() . '/style-admin.css', array(), 1.0, false );
}
add_action( 'admin_head', 'register_custom_admin_css' );
/**
* Move Yoast to bottom of edit screen.
*/
function yoasttobottom() {
return 'low';
}
add_filter( 'wpseo_metabox_prio', 'yoasttobottom' );
/**
* Callback function to insert styleselect into the buttons array.
*
* @param array $buttons List of buttons loaded by WP editor.
*/
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
/**
* Set up additional styles for editor button
*
* @param array $settings List of settings loaded by WP editor.
*/
function tuts_mce_before_init( $settings ) {
$style_formats = array(
array(
'title' => __( 'Positive', '3cb24' ),
'selector' => 'p',
'classes' => 'positive',
),
array(
'title' => __( 'Error', '3cb24' ),
'selector' => 'p',
'classes' => 'negative',
),
array(
'title' => __( 'Warning', '3cb24' ),
'selector' => 'p',
'classes' => 'warning',
),
array(
'title' => __( 'Smaller text', '3cb24' ),
'selector' => 'p',
'classes' => 'has-small-font-size',
),
array(
'title' => __( 'Larger text', '3cb24' ),
'selector' => 'p',
'classes' => 'has-large-font-size',
),
array(
'title' => __( 'Button', '3cb24' ),
'selector' => 'a',
'classes' => 'btn',
),
);
$settings['style_formats'] = wp_json_encode( $style_formats );
$settings['theme_advanced_blockformats'] = 'p,h3,h4';
$settings['theme_advanced_disable'] = 'forecolor';
return $settings;
}
add_filter( 'tiny_mce_before_init', 'tuts_mce_before_init' );
/**
* Add editor fonts/styles.
*/
function my_theme_add_editor_styles() {
add_editor_style( 'style-editor.css' );
}
add_action( 'init', 'my_theme_add_editor_styles' );
/**
* Remove WPCF7 stylesheet - we use our own styles in main CSS.
*/
add_filter( 'wpcf7_load_css', '__return_false' );
/**
* Stop WPCF7 adding P tags to forms.
*/
add_filter( 'wpcf7_autop_or_not', '__return_false' );