-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
101 lines (81 loc) · 2.84 KB
/
functions.php
File metadata and controls
101 lines (81 loc) · 2.84 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
<?php
require_once(get_template_directory() . '/includes/constants.php');
require_once(INCLUDES_DIR . '/class.wp-brunch.php');
require_once(INCLUDES_DIR . '/class.autoloaders.php');
require_once(INCLUDES_DIR . '/wordpress-helpers.php');
class WPTheme extends WPBrunch {
public static function init() {
parent::init();
Autoloaders::init();
add_action('wp_enqueue_scripts', [__CLASS__, 'styleScriptIncludes']);
add_action('after_setup_theme', [__CLASS__, 'themeSupport']);
add_action('after_setup_theme', [__CLASS__, 'customImageSizes']);
add_action('after_setup_theme', [__CLASS__, 'registerNavMenus']);
add_action('init', [__CLASS__, 'includeAdditionalFiles'], LOAD_ON_INIT);
add_filter('script_loader_tag', [__CLASS__, 'deferParsingOfJS'], 10);
// Uncomment action below once you have customised the logo and colours for
// the admin login page
// add_action('login_head', [__CLASS__, 'customLoginLogo']);
}
public static function styleScriptIncludes() {
wp_register_script(
'fontawesome-svg-js',
'//use.fontawesome.com/releases/v5.0.2/js/all.js',
[],
'5.0.2',
true
);
wp_enqueue_script(['jquery', 'underscore', 'fontawesome-svg-js']);
wp_localize_script(
'theme_js',
'wpAjax',
['ajaxurl' => admin_url('admin-ajax.php')]
);
}
public function deferParsingOfJS($tag) {
$scripts_to_exclude = ['jquery', 'underscore'];
foreach($scripts_to_exclude as $exclude_script) {
if(strpos($tag, $exclude_script) !== false) return $tag;
}
return str_replace(' src', ' defer src', $tag);
}
public static function themeSupport() {
add_theme_support('html5', ['search-form']);
add_theme_support('automatic-feed-links');
add_theme_support('post-thumbnails');
add_theme_support('title-tag');
}
public static function customImageSizes() {
add_image_size('hero-banner-image', 1920, 1080, true);
}
public static function registerNavMenus() {
register_nav_menus([
'main_menu' => 'Main navigation menu',
'footer_menu' => 'Footer navigation menu'
]);
new MenuCssRewriter('main_menu', 'page-header__menu');
new MenuCssRewriter('footer_menu', 'page-footer__menu');
}
public static function includeAdditionalFiles() {
new CustomPostTypes();
new CustomMetaboxes();
new ContentHelpers();
if(is_admin()) ThemeAdmin::get_instance();
}
public static function customLoginLogo() {
$admin_logo = PUBLIC_FOLDER . '/images/admin-login-logo.jpg';
?>
<style type="text/css">
.login { background-color: #000; }
.login h1 a {
background-image: url('<?php echo $admin_logo; ?>');
background-size: 100%;
height: 140px;
width: 140px;
}
.login #nav a, .login #backtoblog a { color: #fff; }
</style>
<?php
}
}
WPTheme::init();