-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
224 lines (155 loc) · 6.75 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
<?php
/**
* Starkers functions and definitions
*
* For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
*
* @package WordPress
* @subpackage Starkers
* @since Starkers 4.0
*/
/* ========================================================================================================================
Required external files
======================================================================================================================== */
require_once( 'assets/includes/starkers-utilities.php' );
require_once( 'assets/includes/admin.php' );
//require_once( 'assets/includes/Mobile_Detect.php' );
//require_once( 'assets/includes/custom-post-type.php' );
/*======================================================================================================================== */
add_theme_support( 'post-thumbnails' );
//add_theme_support( 'menus' );
/** NAVIGATION **/
if ( function_exists( 'register_nav_menus' ) ) {
register_nav_menus(
array(
'primary' => 'Primary Nav'
)
);
}
// Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail
function remove_thumbnail_dimensions( $html ){
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 ); // Remove width and height dynamic attributes to thumbnails
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 ); // Remove width and height dynamic attributes to post images
/** footer pagination for archive pages **/
function le_pagination(){
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'type' => 'list',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
}
// Hide email from Spam Bots using a shortcode.
function wpcodex_hide_email_shortcode( $atts , $content = null ) {
if ( ! is_email( $content ) ) {
return;
}
return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
}
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
// Google analytics code
function add_ga_code() { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push( ['_setAccount', 'UA-XXXXX-X'] ); //Update 'UA-XXXXX-X' with valid account id
_gaq.push( ['_trackPageview'] );
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ( 'https:' == document.location.protocol ? 'https://ssl' : 'http://www' ) + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName( 'script' )[0]; s.parentNode.insertBefore( ga, s );
})();
</script>
<?php }
add_action( 'wp_footer', 'add_ga_code' );
add_filter( 'body_class', array( 'Starkers_Utilities', 'add_slug_to_body_class' ) );
// add_image_size( "thumb-mobile", width, height, True );
if( false === get_option("medium_crop") ) {
add_option( "medium_crop", "1" );
} else {
update_option( "medium_crop", "1" );
}
function new_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'new_excerpt_length' );
// minified merged jquery file and sass compiled css
function starkers_script_enqueuer() {
// Reload jquery so there are no conflicts
if( !is_admin() ){
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ( "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ), false, null, true );
wp_enqueue_script( 'jquery' );
}
wp_register_script( 'site', get_template_directory_uri().'/assets/js/min/script.min.js', false, null, true );
wp_enqueue_script( 'site' );
wp_register_style( 'bootstrap', get_stylesheet_directory_uri().'/assets/css/style.css', '', null, 'all' );
wp_enqueue_style( 'bootstrap' );
}
// load jquery which is only required on some pages here
function conditional_scripts(){
if ( is_page( 'pagenamehere' ) ) {
wp_register_script( 'scriptname', get_template_directory_uri() . '/js/scriptname.js', array( 'jquery' ), '1.0.0' ); // Conditional script(s)
wp_enqueue_script( 'scriptname' ); // Enqueue it!
}
}
//add_action( 'wp_print_scripts', 'conditional_scripts' ); // Add Conditional Page Scripts
add_action( 'wp_enqueue_scripts', 'starkers_script_enqueuer' );
function IE_conditionals(){ ?>
<!--[if lt IE 8]>
<p class=chromeframe>Your browser is out of date and insecure.
<a href="http://browsehappy.com/">Upgrade to a different browser</a>
or <a href="http://www.google.com/chromeframe/?redirect=true">
install Google Chrome Frame</a> to experience this site as intended.
</p>
<![endif]-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="<?php echo get_stylesheet_directory_uri(); ?>/assets/js/min/respond.min.js"></script>
<![endif]-->
<?php }
add_filter( 'wp_head', 'IE_conditionals' );
/* ========================================================================================================================
Comments
======================================================================================================================== */
/**
* Custom callback for outputting comments
*
* @return void
* @author Keir Whitaker
*/
function starkers_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
?>
<?php if ( $comment->comment_approved == '1' ): ?>
<li>
<article id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment ); ?>
<h4><?php comment_author_link() ?></h4>
<time><a href="#comment-<?php comment_ID() ?>" pubdate><?php comment_date() ?> at <?php comment_time() ?></a></time>
<?php comment_text() ?>
</article>
<?php endif;
}
// No more jumping for read more link
function no_more_jumping( $post ) {
return '<a href="'.get_permalink($post->ID).'" class="read-more">'.'Continue Reading'.'</a>';
}
add_filter( 'excerpt_more', 'no_more_jumping' );
add_filter( 'the_content_more_link', 'remove_more_jump_link' );
// Remove junk from head
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
?>