-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
243 lines (192 loc) · 7.48 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
<?php
// Add support for post thumbnails, a.k.a. "Featured Images" or "Logos"
add_theme_support( 'post-thumbnails' );
add_action("wp_enqueue_scripts", "auto_version_and_enqueue_scripts", 20);
function auto_version_and_enqueue_scripts() {
// Get last modified timestamp of CSS file in /css/style.css
$csstime = filemtime( get_template_directory() . '/dist/css/style.css' );
// Get last modified timestamp of JS file in /js/main.js
$jtime = filemtime( get_template_directory() . '/dist/js/bundle.js' );
wp_enqueue_style(
'style_css', // handle for style.css
get_template_directory_uri() . '/dist/css/style.css',
array(), // dependencies
$csstime, // version number
false // load in footer
);
wp_enqueue_style( 'google_fonts', 'https://fonts.googleapis.com/css?family=Josefin+Sans:400,400i,600i,700', false );
wp_enqueue_script(
'all_js', // handle for main.js
get_template_directory_uri() . '/dist/js/bundle.js',
array(), // dependencies
$jtime, // version number
true // load in footer
);
}
// Register our menus
function register_theme_menus() {
register_nav_menus (
array(
'primary-menu' => __( 'Primary Menu' )
)
);
}
add_action('init', 'register_theme_menus');
function gallery_default_type_set_link( $settings ) {
$settings['galleryDefaults']['link'] = 'none';
$settings['galleryDefaults']['size'] = 'large';
return $settings;
}
add_filter( 'media_view_settings', 'gallery_default_type_set_link');
function custom_image_size() {
// Set default values for the upload media box
update_option('image_default_size', 'large' );
}
add_filter( 'shortcode_atts_gallery', 'remove_link_from_gallery_images_and_set_size_to_large', 10, 4 );
function remove_link_from_gallery_images_and_set_size_to_large( $out, $pairs, $atts, $shortcode ) {
if (!isset( $atts['link'])) {
$out['link'] = 'none';
}
if (!isset( $atts['size'])) {
$out['size'] = 'large';
}
return $out;
}
// Add additional <li> with mobile menu social icons
function add_social_to_nav( $items, $args ) {
if ( ! function_exists( 'wpse_return_template_part' ) ) {
function wpse_return_template_part( $arg ) {
ob_start();
get_template_part( $arg);
return ob_get_clean();
}
}
if ( function_exists( 'wpse_return_template_part' ) ) {
$social_items = wpse_return_template_part( 'component-social-mobile-nav');
}
$items .= "<li class='nav__item'>"
.$social_items
."</li>";
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_social_to_nav', 10, 2 );
// Add custom nav class to menu items
function custom_nav_class( $classes ) {
$classes[] = 'nav__item';
return $classes;
}
add_filter( 'nav_menu_css_class', 'custom_nav_class', 10, 2 );
// Walker for traversing nav items and customizing output
class Custom_Nav_Walker extends Walker_Nav_Menu {
/**
* Start the element output.
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. May be used for padding.
* @param array|object $args Additional strings. Actually always an
instance of stdClass. But this is WordPress.
* @return void
*/
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
$classes = empty ( $item->classes ) ? array () : (array) $item->classes;
$class_names = join(' ',
apply_filters(
'nav_menu_css_class',
array_filter( $classes ), $item
)
);
! empty ( $class_names )
and $class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= "<li id='menu-item-$item->ID' $class_names>";
! empty( $item->title )
and $attributes .= ' title="' . esc_attr( $item->title ) .'"';
! empty( $item->target )
and $attributes .= ' target="' . esc_attr( $item->target ) .'"';
! empty( $item->xfn )
and $attributes .= ' rel="' . esc_attr( $item->xfn ) .'"';
! empty( $item->url )
and $attributes .= ' href="' . esc_attr( $item->url ) .'"';
$title = apply_filters( 'the_title', $item->title, $item->ID );
$item_output = $args->before
. "<a $attributes>"
. $args->link_before
. $title
. '</a> '
. $args->link_after
. $description
. $args->after;
// Since $output is called by reference we don't need to return anything.
$output .= apply_filters(
'walker_nav_menu_start_el',
$item_output,
$item,
$depth,
$args
);
}
}
// Where Page Pagination
function where_page_paginator() {
$args = array(
'post_type' => 'location',
'order' => 'ASC',
'posts_per_page' => 8
);
$where_page_query = new WP_Query($args);
/** Stop execution if there's only 1 page */
if( $where_page_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $where_page_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="pagination__wrapper"><ul class="pagination">' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li class="pagination__item">%s</li>' . "\n", get_previous_posts_link('prev') );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="pagination__item pagination__item--active"' : ' class="pagination__item"';
printf( '<li%s><a class="pagination__item-link" href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li class="pagination__item">…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="pagination__item pagination__item--active"' : ' class="pagination__item"';
printf( '<li%s><a class="pagination__item-link" href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li class="pagination__item">…</li>' . "\n";
$class = $paged == $max ? ' class="pagination__item pagination__item--active"' : ' class="pagination__item"';
printf( '<li%s><a class="pagination__item-link" href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li class="pagination__item">%s</li>' . "\n", get_next_posts_link('next') );
echo '</ul></div>' . "\n";
}
add_filter('next_posts_link_attributes', 'posts_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_link_attributes');
function posts_link_attributes() {
return 'class="pagination__item-link"';
}
function remove_shortcode_from_index( $content ) {
$content = strip_shortcodes( $content );
return $content;
}
add_filter( 'the_content', 'remove_shortcode_from_index' ); ?>