-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
259 lines (185 loc) · 7.77 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
<?php
/**
* themename functions and definitions
*
* @package themename
*/
/*-------------------------------------------------------------------------------------------*/
/* themename Theme Setup
/*-------------------------------------------------------------------------------------------*/
if ( ! isset( $content_width ) ) {
$content_width = 640; /* pixels */
}
if ( ! function_exists( 'themename_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function themename_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
*/
load_theme_textdomain( 'themename', get_template_directory() . '/languages' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
/* Specify image title, size and positionig */
add_image_size( 'blog-feat', 300, 300, array( 'center', 'center' ) );
// This theme uses wp_nav_menu() in one location.
// Register multiple nav menus this way to hook into the WordPresss API
register_nav_menus(
array(
'primary' => 'Primary Menu',
'blog' => 'Blog Menu',
'footer' => 'Footer Menu',
)
);
/*-------------------------------------------------------------------------------------------*/
/* Enable Active CLass on Menu remove the messy default classes
/*-------------------------------------------------------------------------------------------*/
//Deletes all CSS classes and id's, except for those listed in the array below
function custom_wp_nav_menu($var) {
return is_array($var) ? array_intersect($var, array(
//List of allowed menu classes
'current_page_item',
'current_page_ancestor',
'first',
'last',
'vertical',
'horizontal'
)
) : '';
}
add_filter('nav_menu_css_class', 'custom_wp_nav_menu');
add_filter('nav_menu_item_id', 'custom_wp_nav_menu');
add_filter('page_css_class', 'custom_wp_nav_menu');
//Replaces "current-menu-item" with "active"
function current_to_active($text){
$replace = array(
//List of menu item classes that should be changed to "active"
'current_page_item' => 'active',
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter ('wp_nav_menu','current_to_active');
/*-------------------------------------------------------------------------------------------*/
/* Enable Additional Theme Support
/*-------------------------------------------------------------------------------------------*/
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
) );
/*-------------------------------------------------------------------------------------------*/
/* Enable Post Format Support
/*-------------------------------------------------------------------------------------------*/
add_theme_support( 'post-formats', array(
'aside', 'image', 'video', 'quote', 'link'
) );
}
endif;
add_action( 'after_setup_theme', 'themename_setup' );
/*-------------------------------------------------------------------------------------------*/
/* Remove WP version number from header
/*-------------------------------------------------------------------------------------------*/
remove_action('wp_head', 'wp_generator');
/*-------------------------------------------------------------------------------------------*/
/* Register widget area.
/* @link http://codex.wordpress.org/Function_Reference/register_sidebar
/*-------------------------------------------------------------------------------------------*/
function themename_widgets_init() {
register_sidebar( array(
'name' => __( 'Generic Widget', 'themename' ),
'id' => 'generic-widget',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
));
}
add_action( 'widgets_init', 'themename_widgets_init' );
/*-------------------------------------------------------------------------------------------*/
/* Enqueue theme scripts and styles.
/*-------------------------------------------------------------------------------------------*/
function themename_scripts() {
/* Styles */
/* Base Style */
$cache_buster = date("YmdHi", filemtime( get_template_directory_uri()));
wp_enqueue_style( 'themename-style', get_stylesheet_uri(), array(), $cache_buster, 'all' );
/* Loading External stylesheet via CDn*/
wp_enqueue_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.css', array(), '4.0.1' );
// /* Scripts */
wp_enqueue_script( 'themename-main', get_stylesheet_directory_uri() . '/scripts/themename-main.js', array(), filemtime( get_stylesheet_directory() . '/scripts/themename-main.js' ) , true );
}
add_action( 'wp_enqueue_scripts', 'themename_scripts' );
/*===================================================================================
* Remove automatic p tags in text editor
* =================================================================================*/
remove_filter ('the_content', 'wpautop');
/*===================================================================================
* Load Custom Shortcodes - can add more here
* =================================================================================*/
function button_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'username' => 'username',
'style' => 'style'
), $atts ) );
return '<br><a href="http://twitter.com/' . esc_attr($username) . '" class="twitter-button ' . esc_attr($style) . '" target="_blank"><i class="fa fa-twitter"></i> ' . $content . '</a>';
}
add_shortcode('button', 'button_shortcode');
/*===================================================================================
* Limit Excerpt Length
* =================================================================================*/
function custom_excerpt_length( $length ) {
return 50;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/*===================================================================================
* Function to check for posts by popularity
* =================================================================================*/
function observePostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
} else {
$count++;
update_post_meta($postID, $count_key, $count);
}
}
function fetchPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}
/*===================================================================================
* Customise Login Logo & link to main website
* =================================================================================*/
function customise_login_image() { ?>
<style type="text/css">
body.login #login h1 a {
background: url('') 8px 0 no-repeat transparent;
background-position: center;
height:100px;
width:320px; }
</style>
<?php }
add_action("login_head", "customise_login_image");
add_filter( 'login_headerurl', 'custom_loginlogo_url' );
function custom_loginlogo_url($url) {
return 'http://themename.com';
}