-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
190 lines (173 loc) · 4.88 KB
/
functions.php
File metadata and controls
190 lines (173 loc) · 4.88 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
179
180
181
182
183
184
185
186
187
188
189
190
<?php
$guten_scripts = array(
'fluid-container',
);
$scripts = array(
'strudel',
'nav',
);
$dependencies = array();
$guten_styles = array(
'guten-styles',
'admin-render-both',
);
$stylesheets = array(
'fonts',
'sitewide',
'elements',
'home',
'header',
'footer',
'superberg',
'superelementor',
'admin-render-both',
);
// Assets file loads in js and css needed to render blocks in WP editor
include( plugin_dir_path( __FILE__ ) . 'render-fluid-container.php' );
// Add page slug to the body class
function oppidan_body_class( $classes ) {
global $post;
$slug = $post->post_name;
$classes[] = 'page-' . $slug;
return $classes;
}
add_filter( 'body_class','oppidan_body_class' );
// Theme features
function oppidan_theme_support() {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'title-tag' );
register_block_style(
'core/image',
array(
'name' => 'accent-shadow-cool',
'label' => 'Accent Shadow (Cool)',
'style_handle' => 'admin-render-both',
)
);
register_block_style(
'core/image',
array(
'name' => 'accent-shadow-warm',
'label' => 'Accent Shadow (Warm)',
'style_handle' => 'admin-render-both',
)
);
register_block_style(
'core/columns',
array(
'name' => 'hero',
'label' => 'Hero banner',
'style_handle' => 'admin-render-both',
)
);
register_block_style(
'core/columns',
array(
'name' => 'wide',
'label' => 'Wide',
'style_handle' => 'admin-render-both',
)
);
register_block_style(
'core/columns',
array(
'name' => 'small-img',
'label' => 'Small image',
'style_handle' => 'admin-render-both',
)
);
}
add_action( 'after_setup_theme', 'oppidan_theme_support' );
// Style and script loading
function oppidan_enqueue() {
$style_dir = get_template_directory_uri() . '/css/';
global $stylesheets;
$script_dir = get_template_directory_uri() . '/js/';
global $scripts;
global $dependencies;
foreach ( $stylesheets as $slug ) {
wp_enqueue_style( 'oppidan-' . $slug, $style_dir . $slug . '.css' );
}
wp_enqueue_style(
'oppidan-font-awesome',
get_template_directory_uri() . '/fonts/font-awesome-4.7.0/css/font-awesome.css'
);
foreach ( $scripts as $slug ) {
wp_enqueue_script( 'oppidan-' . $slug, $script_dir . $slug, $dependencies );
}
}
add_action( 'wp_enqueue_scripts', 'oppidan_enqueue' );
// Gutenberg assets
function oppidan_enqueue_blocks() {
$style_dir = get_template_directory_uri() . '/css/';
$script_dir = get_template_directory_uri() . '/js/';
global $guten_scripts;
global $guten_styles;
global $dependencies;
foreach ( $guten_styles as $slug ) {
wp_enqueue_style( 'oppidan-' . $slug, $style_dir . $slug . '.css' );
}
foreach ( $guten_scripts as $slug ) {
wp_enqueue_script( 'oppidan-' . $slug, $script_dir . $slug, $dependencies );
}
}
add_action( 'enqueue_block_editor_assets', 'oppidan_enqueue_blocks' );
// Menu locations
function oppidan_menus() {
$locs = array(
'primary' => 'Primary menu',
'footer' => 'Footer menu',
'socials' => 'Social links',
);
register_nav_menus( $locs );
}
add_action( 'init', 'oppidan_menus' );
// Hook for actions that need to be performed after body load
if ( ! function_exists( 'wp_body_open' ) ) {
function wp_body_open() {
do_action( 'wp_body_open' );
}
}
// (Provided by Wordpress) Filter to make Wordpress 'Read More' button more accessible
function oppidan_read_more_tag( $html ) {
$search_str = '/<a(.*)>(.*)<\/a>/iU';
$replace_str = sprintf( '<div class="read-more-button-wrap"><a$1><span class="faux-button">$2</span> <span class="screen-reader-text">"%1$s"</span></a></div>', get_the_title( get_the_ID() ) );
return preg_replace( $search_str, $replace_str, $html );
}
add_filter( 'the_content_more_link', 'oppidan_read_more_tag' );
// Add type="module" to scripts
function oppidan_scripts_to_modules( $tag, $handle, $src ) {
global $scripts;
foreach( $scripts as $module ) {
$the_handle = 'oppidan-' . $module;
if ( $the_handle == $handle ) {
return '<script type="module" src="' . esc_url( $src ) . '"></script>';
}
}
return $tag;
}
add_filter('script_loader_tag', 'oppidan_scripts_to_modules' , 10, 3);
// Breadcrumbs
function crumb() {
global $wp;
$curr = add_query_arg( array(), $wp->request );
$suburl = explode( '/', $curr );
$subpages = array();
$buildUrl = '/';
$subpages []= array(
'url' => '/',
'title' => 'Home',
);
foreach ( $suburl as $slug ) {
$buildUrl .= $slug . '/';
$id = url_to_postid( $buildUrl );
if ( $id != 0 ) { // Checks whether the parent post is valid
$title = get_the_title( $id );
$subpages []= array(
'url' => $buildUrl,
'title' => $title,
);
}
}
return $subpages;
}