-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
491 lines (428 loc) · 16.9 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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<?php
/**
* Remove Thematic Menu JavaScript
*
* Removes the default Thematic JS scripts (Superfish) completely.
*
* Reference http://thematictheme.com/forums/topic/correct-way-to-prevent-loading-thematic-scripts/
*
*/
function childtheme_remove_superfish(){
remove_theme_support('thematic_superfish');
}
add_action('wp_enqueue_scripts','childtheme_remove_superfish', 9);
/**
* Script Manager
*
* Setup for adding and removing scripts and styling.
*
* Reference http://wpcandy.com/teaches/how-to-load-scripts-in-wordpress-themes/
*
*/
function childtheme_script_manager() {
// wp_register_script template ( $handle, $src, $deps, $ver, $in_footer );
// registers modernizr script, childtheme path, no dependency, no version, loads in footer
wp_register_script('modernizr-js', get_stylesheet_directory_uri() . '/js/modernizr.js', false, false, true);
// registers misc custom script, childtheme path, yes dependency is jquery, no version, loads in footer
wp_register_script('custom-js', get_stylesheet_directory_uri() . '/js/custom.js', array('jquery'), false, true);
// enqueue the scripts for use in theme
wp_enqueue_script ('modernizr-js');
wp_enqueue_script('custom-js');
}
add_action('wp_enqueue_scripts', 'childtheme_script_manager');
// deregister styles
function childtheme_deregister_styles() {
// removes contact form 7 styling
wp_deregister_style('contact-form-7');
// remove like 2 bullshit classes from jetpack on a individual CSS file
wp_deregister_style('jetpack-widgets');
// remove 2 more bullshit classes from jetpack, same as above
wp_deregister_style('jetpack-subscriptions');
}
add_action('wp_print_styles', 'childtheme_deregister_styles', 100);
// deregister scripts
function childtheme_deregister_scripts() {
// removes themaitc-js which has more Superfish scripts
wp_dequeue_script('thematic-js');
// remove some bs gravatar script jetpack loads
wp_deregister_script('devicepx');
if ( ! is_page('contact') ) {
// remove contact form7 styles on all pages but contact page
wp_dequeue_script('contact-form-7');
}
}
add_action( 'wp_print_scripts', 'childtheme_deregister_scripts', 100 );
/**
* Remove jQuery Migrate
*
* Removes jQuery Migrate, don't do this unless dev in charge of the site and
* constantly working on it, this is just a way to cut out one http request.
* just delete this function.
*
* Reference http://aahacreative.com/2013/08/05/remove-jquery-migrate-wordpress-36/
*
*/
function dequeue_jquery_migrate( &$scripts){
if( !is_admin() ) {
$scripts->remove( 'jquery');
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
}
}
add_filter( 'wp_default_scripts', 'dequeue_jquery_migrate' );
/**
* Modernizr add 'no-js' class
*
* This filter adds the 'no-js' class to the HTML tag, which Modernizr will remove
* (if Javascript is enabled) and replace it with a "js" class. This is super useful
* for providing CSS fallbacks, but Modernizr does a ton more.
*
* Reference http://modernizr.com/docs/
*
*/
function childtheme_html_class( $class_att ) {
$class_att = "no-js";
return $class_att;
}
add_filter( 'thematic_html_class', 'childtheme_html_class' );
/**
* Add Favicon
*
* The Favicon is actually really complicated, but a quick and dirty method is to at
* least add a 32x32 ,ico file (at the least).
*
* Reference http://www.jonathantneal.com/blog/understand-the-favicon/
* Photoshop Plugin to save ICO files http://www.telegraphics.com.au/sw/
*
*/
function childtheme_add_favicon() { ?>
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
<?php }
add_action('wp_head', 'childtheme_add_favicon');
/**
* Clean up <head> of Site
*
* Wordpress by default throws in all kinds of relational links, for SEO purposes,
* sometimes they work and sometimes they don't. A Plugin like WordPress SEO can
* handle some of these also, but others are not included.
*
* Reference http://scottnix.com/polishing-thematics-head/
*
*/
// remove really simple discovery
remove_action('wp_head', 'rsd_link');
// remove windows live writer xml
remove_action('wp_head', 'wlwmanifest_link');
// remove index relational link
remove_action('wp_head', 'index_rel_link');
// remove parent relational link
remove_action('wp_head', 'parent_post_rel_link');
// remove start relational link
remove_action('wp_head', 'start_post_rel_link');
// remove prev/next relational link
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
// remove short link
remove_action('wp_head', 'wp_shortlink_wp_head');
/*
* WordPress SEO hack
*
* Removes the rel="next" and rel="previous" meta tags. The way my site is setup makes these
* useless and as an SEO type person it bugs me, otherwise no normal person would care.
*
*/
function genesis() {}
/*
* Remove H1 from Blog Description that appears on front page only.
*
* I don't want multiple H1's, technically the override below could be a lot shorter, but I
* want the ability to modify it for when I do switch from showing a blog post on the front
* page to a really custom one, so I will correct this later.
*
*/
function childtheme_override_blogdescription() {
if ( is_home() || is_front_page() ) {
$tag = 'p';
} else {
$tag = 'p';
}
echo "\t<$tag id=\"blog-description\" class=\"tagline\">". get_bloginfo( 'description', 'display' ) . "</$tag>\n\n";
}
/**
* Register Two Additional Menus
*
* Not always needed, but a lifesaver if you need more custom menus for widget areas.
*
*/
function childtheme_register_menus() {
register_nav_menu( 'secondary-menu', 'Secondary Menu' );
register_nav_menu( 'tertiary-menu', 'Tertiary Menu' );
}
add_action('thematic_child_init', 'childtheme_register_menus');
/**
* Remove Widgets in Admin.
*
* All this does is removes the widgets from being selected in the admin. This is helpful
* if you aren't using the widgets, no point in looking at them or having to explain why
* they are there.
*
*/
function childtheme_hide_areas($content) {
unset($content['Index Top']);
unset($content['Index Insert']);
unset($content['Index Bottom']);
unset($content['Single Top']);
unset($content['Single Insert']);
unset($content['Single Bottom']);
unset($content['Page Top']);
unset($content['Page Bottom']);
return $content;
}
add_filter('thematic_widgetized_areas', 'childtheme_hide_areas');
/**
* Responsive Menu Structure
*
* Modified to add toggle in link format instead of <h3> that is defaulted from the parent
* theme. his basic structure comes from a mobile pattern from the link below.
*
* Reference http://codepen.io/bradfrost/pen/vljdx
*
*/
function childtheme_override_access() {
?>
<div id="access" role="navigation">
<a class="menu-toggle" href="#">Menu</a>
<?php
if ( ( function_exists( 'has_nav_menu' ) ) && ( has_nav_menu( apply_filters( 'thematic_primary_menu_id', 'primary-menu' ) ) ) ) {
echo wp_nav_menu(thematic_nav_menu_args());
} else {
echo thematic_add_menuclass( wp_page_menu( thematic_page_menu_args () ) );
}
?>
</div><!-- #access -->
<?php
}
/**
* Single Post for Blog
*
* Shows a full single post on homepage, instead of a default of 5
*
* Reference: http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
*
*/
function childtheme_home_pagesize( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( is_home() ) {
// Display only 1 post for the original blog archive
$query->set( 'posts_per_page', 1 );
return;
}
}
add_action( 'pre_get_posts', 'childtheme_home_pagesize', 1 );
/**
* Modify Navigational Elements
*
* The Navigation Above feature of Thematic is pretty silly (and ugly), so that is
* completely removed. For the Navigation Below, we remove it on single pages since it
* can link to totally unrelated content which doesn't make much sense in most cases.
*
*/
// override completely removes nav above functionality
function childtheme_override_nav_above() {
// silence
}
// keep nav below, but this setup changes the wording (adding plural) on category sections which show more than one post.
function childtheme_override_nav_below() {
if (is_single() || is_home()) { ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php previous_post_link('%link', '<span class="meta-nav"></span> Older Post'); ?> </div>
<div class="nav-next"><?php next_post_link('%link', 'Newer Post <span class="meta-nav"></span>'); ?> </div>
<?php }
else { ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav"></span> Older Posts', 'thematic')) ?></div>
<div class="nav-next"><?php previous_posts_link(__('Newer Posts <span class="meta-nav"></span>', 'thematic')) ?></div>
<?php } ?>
</div>
<?php }
/**
* Thematic Featured Image Size
*
* Appears on anything with an excerpt set, the default is 100x100 which is ridiculously
* small, this swaps it out for a more manageable 300x300, but can be easily changed by
* modifying the sizes.
*
*/
// add_image_size( 'category-image', 750 );
function childtheme_post_thumb_size($size) {
$size = array(750,300);
return $size;
}
add_filter('thematic_post_thumb_size', 'childtheme_post_thumb_size');
// add read more on categories to match wp read more
function new_excerpt_more( $more ) {
return '... <a class="more-link" href="' . get_permalink() . '">Read More</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
/*
* Thematic Featured Image Text (attributes)
*
* All this does is remove the "Permalink to" that appears before the image title, just
* bugs me, these should be stripped from the parent Thematic Theme, but it is a small battle
* so I will let it slide for now.
*/
function childtheme_post_thumb_attr($attr) {
$attr = array('title' => sprintf( esc_attr__('%s', 'thematic'), the_title_attribute( 'echo=0' ) ) );
return $attr;
}
add_filter('thematic_post_thumb_attr', 'childtheme_post_thumb_attr');
/*
* Modify Widget Titles
*
* Thematic now inputs an H1 for the asides, in HTML5 this is ok, but SEO's will cringe.
* I haven't really seen any data showing that using H1's is fine for search engines,
* and from what I have seen no one has really been bold enough to jump on that band
* wagon, so this reverts them back to H4's instead.
*
*/
function childtheme_before_widgettitle( $content ) {
$content = "<h4 class=\"widgettitle\">";
return $content;
}
add_filter( 'thematic_before_title', 'childtheme_before_widgettitle');
function childtheme_after_widgettitle( $content ) {
$content = "</h4>\n";
return $content;
}
add_filter( 'thematic_after_title', 'childtheme_after_widgettitle');
/*
* Modify Search Widget
*
* This is pretty much required for responsive sites, you can set it with CSS, but this
* is a backup to make sure the box isn't super big. Also the second function allows you
* to change the text, the default text is stupid, "Type to search and hit enter" or
* something like that, way too long.
*
*/
// shorten the input box length
function childtheme_thematic_search_form_length() {
return "16";
}
add_filter('thematic_search_form_length', 'childtheme_thematic_search_form_length');
// change the default search box text
function childtheme_search_field_value() {
return "Search";
}
add_filter('search_field_value', 'childtheme_search_field_value');
/**
* Modify the Post Header and Post Footer
*
* Moves the elemenets and changes structure of the postheader and postfooter to rearrange
* things for a cleaner look, moves date below post and adds icon fonts in a list style
* format instead of the default which is just a single line.
*
*/
// kill the post header information, loading this below in the post footer
function childtheme_override_postheader_postmeta() {
// silence!
}
// example of changing up the display of the entry-utility for a different look
function childtheme_override_postfooter() {
$post_type = get_post_type();
$post_type_obj = get_post_type_object($post_type);
$tagsection = get_the_tags();
// Display nothing for "Page" post-type
if ( $post_type == 'page' ) {
$postfooter = '';
// For post-types other than "Pages" press on
} else {
$postfooter = '<footer class="entry-utility">';
$postfooter .= '<ul class="main-utilities">';
$postfooter .= '<li class="icon-calendar">' . thematic_postmeta_entrydate() . '</li>';
// $postfooter .= '<li class="icon-folder">' . thematic_postfooter_postcategory() . '</li>'; // disable tags/categories till I fix them
$postfooter .= '<li class="icon-comment">' . thematic_postfooter_postcomments() . '</li>';
if ( $tagsection ) {
// $postfooter .= '<li class="icon-tag">' . thematic_postfooter_posttags() . '</li>';
}
if ( is_user_logged_in() ) {
$postfooter .= '<li class="icon-pencil">' . thematic_postfooter_posteditlink() . '</li>';
}
$postfooter .= '</ul>';
$postfooter .= "\n\n\t\t\t\t\t</footer><!-- .entry-utility -->\n";
}
// Put it on the screen
echo apply_filters( 'thematic_postfooter', $postfooter ); // Filter to override default post footer
}
// removes the "Published" from the date in the postfooter, also removes seperator " | "
function childtheme_override_postmeta_entrydate() {
$entrydate = '<span class="entry-date">';
$entrydate .= get_the_time(thematic_time_display());
$entrydate .= '</span>';
return apply_filters('thematic_postmeta_entrydate', $entrydate);
}
// remove unneeded code from postcategory
function childtheme_override_postfooter_postcategory() {
$postcategory = "\n\n\t\t\t\t\t\t" . '<span class="cat-links">';
if (is_single()) {
$postcategory .= __('Categories ', 'thematic') . get_the_category_list(', ');
$postcategory .= '</span>';
$posttags = get_the_tags();
if ( !$posttags ) {
$postcategory .= '';
}
} elseif ( is_category() && $cats_meow = thematic_cats_meow(', ') ) {
$postcategory .= __('Also posted in ', 'thematic') . $cats_meow;
$postcategory .= '</span>' . "\n\n\t\t\t\t\t\t";
} else {
$postcategory .= __('Posted in ', 'thematic') . get_the_category_list(', ');
$postcategory .= '</span>' . "\n\n\t\t\t\t\t\t";
}
return apply_filters('thematic_postfooter_postcategory',$postcategory);
}
// remove unneeded code from posttags
function childtheme_override_postfooter_posttags() {
if ( is_single() && !is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$tagtext = __('','thematic');
$posttags = get_the_tag_list("<span class=\"tag-links\">$tagtext",', ','</span> ');
} elseif ( is_single() ) {
$tagtext = __('','thematic');
$posttags = get_the_tag_list("<span class=\"tag-links\">$tagtext",', ','</span> ');
} elseif ( is_tag() && $tag_ur_it = thematic_tag_ur_it(', ') ) {
$posttags = '<span class="tag-links">' . __('Also tagged ', 'thematic') . $tag_ur_it . '</span>' . "\n\n\t\t\t\t\t\t";
} else {
$tagtext = __('','thematic');
$posttags = get_the_tag_list("<span class=\"tag-links\">$tagtext",', ','</span>' . "\n\n\t\t\t\t\t\t");
}
return apply_filters('thematic_postfooter_posttags',$posttags);
}
/*
* Social Font Icons
*
* Section for a few social icon boxes, these are handled through icon fonts, there is
* text available so they are somewhat more usable.
*
*/
function childtheme_social_icon_fonts() { ?>
<aside class="aside social">
<section>
<ul class="social-icons">
<li class="social-twitter"><a class="icon-twitter" href="http://twitter.com/usabilitydick" title="Twitter"><span>Twitter</span></a></li>
<li class="social-codepen"><a class="icon-codepen" href="http://codepen.io/scottnix" title="Codpen"><span>Codepen</span></a></li>
<li class="social-github"><a class="icon-github" href="https://github.com/scottnix" title="Github"><span>Github</span></a></li>
<li class="social-rss"><a class="icon-rss" href="http://feeds.feedburner.com/snix" title="RSS"><span>RSS</span></a></li>
</ul>
</section>
</aside>
<?php }
add_action('thematic_belowmainasides', 'childtheme_social_icon_fonts');
// Fucking emojis added in WP
//
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
}
add_action( 'init', 'disable_emojis' );