-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.php
411 lines (356 loc) · 13.8 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<?php
/**
* Herringbone Theme Functions.php config file.
*
* @package herringbone
* @author Jefferson Real <[email protected]>
* @copyright Copyright (c) 2022, Jefferson Real
*/
/**
* Load the PHP autoloader from it's own file
*/
require_once(get_template_directory() . '/classes/autoload.php');
/**
* WordPress hooks for this theme.
*/
use Jefferson\Herringbone\Hooks;
$hooks = new Hooks;
/**
* Enqueue scripts and styles
*/
function enqueue_scripts_and_styles() {
wp_enqueue_style( 'style_css', get_template_directory_uri() . '/style.css', array(), filemtime(get_template_directory() . '/style.css'), 'all');
// If not in admin area
if (!is_admin() && $GLOBALS['pagenow'] != 'wp-login.php') {
wp_enqueue_script( 'hb_bundle_js', get_template_directory_uri() . '/js/bundle.js', array (), '0.1', true );
// De-register wp jquery and use CDN
wp_deregister_script('jquery');
wp_enqueue_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js', array (), '3.6.0', true );
// Other front end resources
wp_register_script( 'gsap', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js', array( 'jquery' ), '3.9.1', true );
// CSSRule this is part of core but there's a separate CDN?
wp_register_script( 'gsap_cssrule', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/CSSRulePlugin.min.js', array( 'gsap' ), '3.9.1', true );
wp_register_script( 'gsap_scrolltrigger', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/ScrollTrigger.min.js', array( 'gsap' ), '3.9.1', true );
wp_register_script( 'svgWheel_js', get_template_directory_uri() . '/animation/svgWheel/svgWheel.js', array( 'gsap_cssrule' ), '1.0', true );
//wp_enqueue_style( 'jetbrains', 'https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap', array(), time() , 'all');
}
global $template;
if ( !is_admin() && basename( $template ) == 'landing-page.php') {
bigup_remove_wp_block_library_css();
}
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts_and_styles' );
function bigup_remove_wp_block_library_css() {
wp_dequeue_style( 'wp-block-library' ); // Gutenburg CSS
wp_dequeue_style( 'wp-block-library-theme' ); // Gutenburg CSS
wp_dequeue_style( 'wc-blocks-style' ); // WooCommerce block CSS
}
// ======================================================= Basic WordPress setup
/**
* Disable plugin auto updates
*/
//add_filter( 'auto_update_plugin', '__return_false' );
/**
* Disable theme auto updates
*/
//add_filter( 'auto_update_theme', '__return_false' );
/**
* Register widget area.
*/
function herringbone_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Left Sidebar', 'herringbone' ),
'id' => 'sidebar-left',
'description' => esc_html__( 'Used for article contents and includes right sidebar content at mid-width.', 'herringbone' ),
'before_widget' => '<section id="%1$s" class="sauce widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h3 class="widget_title">',
'after_title' => '</h3>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Right Sidebar', 'herringbone' ),
'id' => 'sidebar-right',
'description' => esc_html__( 'Used for related content and unimportant stuff.', 'herringbone' ),
'before_widget' => '<section id="%1$s" class="sauce widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h3 class="widget_title">',
'after_title' => '</h3>',
)
);
}
add_action( 'widgets_init', 'herringbone_widgets_init' );
if ( ! function_exists( 'herringbone_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function herringbone_setup() {
/*
* Make theme available for translation.
* Translations to be filed in the /languages/ directory.
*/
load_theme_textdomain( 'herringbone', get_template_directory() . '/languages' );
/*
* Let WordPress manage the document title.
* Wordpress will dynamically populate the title tag using the page H1.
*/
// Handled by HB SEO functionality
//add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*/
add_theme_support( 'post-thumbnails' );
/*
* Enable custom image sizes and set the sizes required for the theme
*/
//add_theme_support( 'pop-up-banner' );
//add_image_size( 'service-tile', 960, 960, TRUE );
//add_image_size( 'review-avatar', 150, 150, TRUE );
//add_image_size( 'full-width-banner', 1920, 480, TRUE );
//add_image_size( 'page-featured', 615, 615, TRUE );
/*
* Register WordPress wp_nav_menu() locations
*
* This option exists in the wp_nav_menu function:
*
* "'fallback_cb'
* (callable|false) If the menu doesn't exist, a callback function will fire.
* Default is 'wp_page_menu'. Set to false for no fallback."
*
* This means where the user hasn't set a menu in the theme settings, for instance,
* straight after theme install, WP will display a meaninglesss pages menu which
* makes the theme look broken. TODO: A FALLBACK MUST BE PUT IN PLACE
*
*/
register_nav_menus(
array(
'mobile-popup-menu' => esc_html__( 'Mobile Popup Menu', 'herringbone' ),
'global-primary-menu' => esc_html__( 'Global Header Menu', 'herringbone' ),
'global-secondary-menu' => esc_html__( 'Global Footer Menu', 'herringbone' ),
'global-legal-links' => esc_html__( 'Global Legal Links', 'herringbone' ),
'landing-page-primary-menu' => esc_html__( 'Landing Page Header Menu', 'herringbone' ),
'landing-page-secondary-menu' => esc_html__( 'Landing Page Footer Menu', 'herringbone' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
)
);
/**
* Add theme support for selective refresh for widgets.
*/
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*/
add_theme_support(
'custom-logo',
array(
'height' => 1000,
'width' => 1000,
'flex-width' => true,
'flex-height' => true,
)
);
}
endif;
add_action( 'after_setup_theme', 'herringbone_setup' );
// ================================================================= SEO Cleanup
/**
* Return a title without prefix for every type used in the get_the_archive_title().
*/
add_filter('get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_year() ) {
$title = get_the_date( _x( 'Y', 'yearly archives date format' ) );
} elseif ( is_month() ) {
$title = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
} elseif ( is_day() ) {
$title = get_the_date( _x( 'F j, Y', 'daily archives date format' ) );
} elseif ( is_tax( 'post_format' ) ) {
if ( is_tax( 'post_format', 'post-format-aside' ) ) {
$title = _x( 'Asides', 'post format archive title' );
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
$title = _x( 'Galleries', 'post format archive title' );
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
$title = _x( 'Images', 'post format archive title' );
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
$title = _x( 'Videos', 'post format archive title' );
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
$title = _x( 'Quotes', 'post format archive title' );
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
$title = _x( 'Links', 'post format archive title' );
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
$title = _x( 'Statuses', 'post format archive title' );
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
$title = _x( 'Audio', 'post format archive title' );
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
$title = _x( 'Chats', 'post format archive title' );
}
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
} else {
$title = __( 'Archives' );
}
return $title;
});
/**
* Clean default WP bloat from wp_head hook
*/
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
// rss feeds
// remove_action( 'wp_head', 'feed_links', 2 );
// remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
/**
* Remove default title meta function
*/
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
/**
* Remove USERS from sitemap
*/
add_filter( 'wp_sitemaps_add_provider', function ($provider, $name) {
return ( $name == 'users' ) ? false : $provider;
}, 10, 2);
// ================================================== Herringbone admin settings
/**
* Add Herringbone admin menu option to sidebar
*/
function herringbone_settings_add_menu() {
$hb__icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMzIgMTMyIj48cGF0aCBmaWxsPSIjMDAwIiBkPSJNMCAwdjEzYzAgNSAwIDEwIDggMTNsNTggMjcgNTgtMjdjOC0zIDgtOCA4LTEzVjBMNzQgMjZjLTggNC04IDktOCAxNCAwLTUgMC0xMC04LTE0em0wIDQwdjEzYzAgNCAwIDEwIDggMTNsNTggMjcgNTgtMjdjOC0zIDgtOSA4LTEzVjQwTDc0IDY2Yy04IDQtOCA5LTggMTMgMC00IDAtOS04LTEzem0wIDM5djE0YzAgNCAwIDkgOCAxM2w1OCAyNiA1OC0yNmM4LTQgOC05IDgtMTNWNzlsLTU4IDI3Yy04IDMtOCA5LTggMTMgMC00IDAtMTAtOC0xM3oiPjwvcGF0aD48L3N2Zz4=';
add_menu_page(
'Herringbone Theme Settings',//page_title
'Herringbone', //menu_title
'manage_options', //capability
'herringbone-settings', //menu_slug
'', //function
$hb__icon, //icon_url
4 //position
);
add_submenu_page(
'herringbone-settings', //parent_slug
'Herringbone Theme Settings',//page_title
'Theme Settings', //menu_title
'manage_options', //capability
'herringbone-settings', //menu_slug
'herringbone_settings_page', //function
1 //position
);
}
add_action( 'admin_menu', 'herringbone_settings_add_menu' );
/**
* Create Herringbone Global Settings Page
*/
function herringbone_settings_page() {
$hb__icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMzIgMTMyIj48cGF0aCBmaWxsPSIjMDAwIiBkPSJNMCAwdjEzYzAgNSAwIDEwIDggMTNsNTggMjcgNTgtMjdjOC0zIDgtOCA4LTEzVjBMNzQgMjZjLTggNC04IDktOCAxNCAwLTUgMC0xMC04LTE0em0wIDQwdjEzYzAgNCAwIDEwIDggMTNsNTggMjcgNTgtMjdjOC0zIDgtOSA4LTEzVjQwTDc0IDY2Yy04IDQtOCA5LTggMTMgMC00IDAtOS04LTEzem0wIDM5djE0YzAgNCAwIDkgOCAxM2w1OCAyNiA1OC0yNmM4LTQgOC05IDgtMTNWNzlsLTU4IDI3Yy04IDMtOCA5LTggMTMgMC00IDAtMTAtOC0xM3oiPjwvcGF0aD48L3N2Zz4=';
?>
<div class="wrap">
<h1>
<span>
<img style="max-height: 1em;margin-right: 0.5em;vertical-align: middle;" src="
<?php echo $hb__icon ?>"
/>
</span>
Herringbone Settings
</h1>
<form method="post" action="options.php">
<?php
settings_fields( 'section' );
do_settings_sections( 'theme-options' );
submit_button();
?>
</form>
</div>
<?php }
/*
* Add options fields to the admin page
*
// Codepen
function setting_codepen() { ?>
<input type="text" name="codepen" id="codepen" value="<?php echo get_option( 'codepen' ); ?>" />
<?php }
// Instagram
function setting_instagram() { ?>
<input type="text" name="instagram" id="instagram" value="<?php echo get_option('instagram'); ?>" />
<?php }
// Facebook
function setting_facebook() { ?>
<input type="text" name="facebook" id="facebook" value="<?php echo get_option('facebook'); ?>" />
<?php }
*/
/*
* Tell WordPress to build the admin page
*
function herringbone_settings_page_setup() {
add_settings_section( 'section', 'Social Links', null, 'theme-options' );
add_settings_field( 'codepen', 'Codepen URL', 'setting_codepen', 'theme-options', 'section' );
add_settings_field( 'instagram', 'Instagram URL', 'setting_instagram', 'theme-options', 'section' );
add_settings_field( 'facebook', 'Facebook URL', 'setting_facebook', 'theme-options', 'section' );
register_setting( 'section', 'codepen' );
register_setting( 'section', 'instagram' );
register_setting( 'section', 'facebook' );
}
add_action( 'admin_init', 'herringbone_settings_page_setup' );
*/
// =========================================================== Custom Post Types
/* Custom Post Type
function create_my_custom_post() {
register_post_type( 'my-custom-post',
array(
'labels' => array(
'name' => __( 'My Custom Post' ),
'singular_name' => __( 'My Custom Post' ),
),
'public' => true,
'has_archive' => true,
'supports' => array( // Define post elements
'title', // the_title()
'editor', // the_content()
'thumbnail', // the_post_thumbnail()
'custom-fields'
),
'taxonomies' => array( // Add ways to group posts
'post_tag', // Tags
'category', // Categories
)
)
);
register_taxonomy_for_object_type( 'category', 'my-custom-post' );
register_taxonomy_for_object_type( 'post_tag', 'my-custom-post' );
}
add_action( 'init', 'create_my_custom_post' );
*/