-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
389 lines (306 loc) · 11.4 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
<?php
/*
BOSTON HASSLE Theme Functions
Author: Kay Belardinelli
URL: http://kangabell.co
*/
/************* BASICS ***************/
if ( ! defined( 'BHASS_VERSION' ) ) {
// Replace the version number of the theme on each release.
define( 'BHASS_VERSION', '2.4' );
}
// set maximum allowed width for content
if ( ! isset( $content_width ) )
$content_width = 1400;
// remove WP version from RSS
add_filter('the_generator', 'bhass_rss_version');
// clean up gallery output in wp
add_filter('gallery_style', 'bhass_gallery_style');
// remove p tags from category description
remove_filter('term_description','wpautop');
// enqueue base scripts and styles
add_action('wp_enqueue_scripts', 'bhass_scripts_and_styles', 999);
// launching this stuff after theme setup
add_action('after_setup_theme','bhass_theme_support');
// add stuff to the wordpress Customizer
add_action( 'customize_register', 'bhass_customize_register' );
// adding sidebars to Wordpress (these are created in functions.php)
add_action( 'widgets_init', 'bhass_register_sidebars' );
// adding the search form
add_filter( 'get_search_form', 'bhass_wpsearch' );
// cleaning up random code around images & blockquotes
add_filter('the_content', 'bhass_filter_ptags_on_images');
add_filter('the_content', 'bhass_filter_ptags_on_blockquotes');
// cleaning up excerpt
add_filter('excerpt_more', 'bhass_excerpt_more');
// shorter excerpt
add_filter( 'excerpt_length', 'bhass_lengthen_excerpt', 999 );
// add class to excerpt paragraph
add_filter( "the_excerpt", "add_excerpt_class" );
// modify output of WordPress Popular Posts plugin
add_filter( 'wpp_custom_html', 'bhass_popular_posts_html', 10, 2 );
// Add support for responsive embedded content (YouTube, Vimeo, etc.).
add_theme_support( 'responsive-embeds' );
/*********************
CLEANUP
*********************/
// remove WP version from RSS
function bhass_rss_version() { return ''; }
// remove WP version from scripts
function bhass_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
// remove injected CSS from gallery
function bhass_gallery_style($css) {
return preg_replace("!<style type='text/css'>(.*?)</style>!s", '', $css);
}
// remove the p from around imgs & blockquotes (http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/)
function bhass_filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
function bhass_filter_ptags_on_blockquotes($content){
return preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $content);
}
// Change "[...]more>>" to "...".
function bhass_excerpt_more($more) {
global $post;
return '...';
}
// Shorten excerpt length
function bhass_lengthen_excerpt( $length ) {
return 22;
}
// Add a class to excerpt paragraph
function add_excerpt_class( $excerpt ) {
$excerpt = str_replace( "<p", "<p class=\"excerpt\"", $excerpt );
return $excerpt;
}
// Get name of first category in categories array
function category_name() {
$category = get_the_category();
$event_id = get_the_ID();
$event_cats = wp_get_object_terms( $event_id, array( 'tribe_events_cat' ) );
if ( empty( $event_cats ) ) { // not an event
$name = $category[0]->cat_name;
} elseif ( class_exists( 'Tribe__Events__Main' ) ) {
$name = $event_cats[0]->name;
} else { // fallback if events plugin is missing
$name = $category[0]->cat_name;
}
return '<span class="category">' . $name . '</span>';
}
function short_title() {
$title = get_the_title();
return wp_trim_words( $title, 14, '...' );
}
/*********************
SCRIPTS & ENQUEUEING
*********************/
// loading jquery and reply script
function bhass_scripts_and_styles() {
if (!is_admin()) {
// main stylesheet
// wp_register_style( 'bhass-stylesheet', get_stylesheet_directory_uri() . '/library/stylesheets/screen.css', array(), filemtime( plugin_dir_path( __FILE__ ) . '/library/stylesheets/screen.css' ), 'all' );
wp_enqueue_style( 'bhass-stylesheet', get_template_directory_uri() . '/library/stylesheets/screen.css', array(), BHASS_VERSION );
// theme scripts file
wp_register_script( 'bhass-js', get_stylesheet_directory_uri() . '/library/scripts/scripts.js', array( 'jquery' ), '', true );
// enqueue styles and scripts
wp_enqueue_style( 'bhass-stylesheet' );
wp_enqueue_script( 'bhass-js' );
// create site url variable to be used in js
$translation_array = array( 'templateUrl' => get_stylesheet_directory_uri() );
wp_localize_script( 'bhass-js', 'wpurl', $translation_array );
}
}
/*********************
"THE EVENTS CALENDAR"
Functions
*********************/
if ( class_exists( 'Tribe__Events__Main' ) ) {
require get_template_directory() . '/plugins/theeventscalendar.php';
}
/*********************
THEME SUPPORT
*********************/
// Adding WP 3+ Functions & Theme Support
function bhass_theme_support() {
// rss thingy
add_theme_support('automatic-feed-links');
// wp menus
add_theme_support( 'menus' );
// registering wp3+ menus
register_nav_menus(
array(
'main-nav-top' => __( 'Main Menu First Section', 'bhass' ),
'main-nav-categories' => __( 'Main Menu Categories', 'bhass' ),
'main-nav-links' => __( 'Main Menu Second Links', 'bhass' ),
'main-nav-buttons' => __( 'Main Menu Buttons', 'bhass' )
)
);
// featured images
add_theme_support( 'post-thumbnails' );
add_image_size( 'grid-thumb', 560, 300, array( 'center', 'center') );
add_image_size( 'grid-large', 1120, 600, array( 'center', 'center') );
} /* end bhass theme support */
/*********************
CUSTOMIZER
*********************/
function bhass_customize_register( $wp_customize ) {
// add customizable logo
$wp_customize->add_setting( 'bhass_logo', array(
'sanitize_callback' => 'esc_url_raw',
) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'bhass_logo', array(
'label' => __( 'Logo', 'bhass' ),
'section' => 'title_tagline',
'priority' => 1,
'settings' => 'bhass_logo',
) ) );
// add customizable subfooter text
$wp_customize->add_setting( 'sub_footer' );
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'sub_footer',
array(
'label' => __( 'Sub-footer Text', 'bhass' ),
'section' => 'title_tagline',
'settings' => 'sub_footer',
'type' => 'text'
)
)
);
}
/*********************
MENUS & NAVIGATION
*********************/
// main menu top area
function bhass_main_nav_top() {
wp_nav_menu(array(
'container' => false,
'menu' => __( 'Main Menu First Area', 'bhass' ),
'theme_location' => 'main-nav-top',
'depth' => 2,
));
}
// main menu categories area
function bhass_main_nav_categories() {
wp_nav_menu(array(
'container' => false,
'menu' => __( 'Main Menu Categories Area', 'bhass' ),
'theme_location' => 'main-nav-categories',
'depth' => 2,
));
}
// main menu links area
function bhass_main_nav_links() {
wp_nav_menu(array(
'container' => false,
'menu' => __( 'Main Menu Links Area', 'bhass' ),
'theme_location' => 'main-nav-links',
'depth' => 2,
// 'fallback_cb' => 'bhass_main_nav_fallback'
));
}
// main menu buttons area
function bhass_main_nav_buttons() {
wp_nav_menu(array(
'container' => false,
'menu' => __( 'Main Menu Buttons Area', 'bhass' ),
'theme_location' => 'main-nav-buttons',
'depth' => 1,
));
}
/************* MODIFIED TITLE ********************/
// makes a nicely formatted title to go in the head of the document
function bhass_wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() )
return $title;
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";
return $title;
}
add_filter( 'wp_title', 'bhass_wp_title', 10, 2 );
/************* ACTIVE SIDEBARS ********************/
function bhass_register_sidebars() {
register_sidebar(array(
'id' => 'sidebar',
'name' => __('Sidebar', 'bhass'),
'description' => __('The sidebar for the archive/category pages.', 'bhass'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'id' => 'sidebar_events',
'name' => __('Events Sidebar', 'bhass'),
'description' => __('The sidebar for the events page.', 'bhass'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'id' => 'sidebar_page',
'name' => __('Page Sidebar', 'bhass'),
'description' => __('The sidebar for the pages using the "Two-Column Page" template.', 'bhass'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
register_sidebar(array(
'id' => 'footer_left',
'name' => __('Footer: Left', 'bhass'),
'description' => __('Left section of the footer.', 'bhass'),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array(
'id' => 'footer_middle',
'name' => __('Footer: Middle', 'bhass'),
'description' => __('Middle section of the footer.', 'bhass'),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array(
'id' => 'footer_right',
'name' => __('Footer: Right', 'bhass'),
'description' => __('Right section of the footer.', 'bhass'),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
}
/************* SEARCH FORM LAYOUT *****************/
// Search Form
function bhass_wpsearch($form) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<label for="s" class="visually-hidden">Search</label><input type="search" value="' . get_search_query() . '" name="s" id="s" placeholder="Search..." />
<button type="submit"><span class="visually-hidden">Go</span><span class="icon-search"></span></button>
</form>';
return $form;
}
/************* ARTICLE BACKGROUND IMAGES *****************/
// show the featured images. if no featured image, show placeholder as fallback
function bhass_article_img() {
if ( has_post_thumbnail() ) {
the_post_thumbnail_url('grid-thumb');
} else {
echo get_template_directory_uri() . '/library/img/placeholder.jpg';
}
}
?>