forked from bbone87/ic-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·197 lines (170 loc) · 5.64 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
<?php
foreach (glob(dirname(__FILE__).'/includes/*.php') as $filename)
require_once($filename);
//Add Featured Image Support
add_theme_support('post-thumbnails');
// Clean up the <head>
add_action('init', 'removeHeadLinks');
function removeHeadLinks() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
}
remove_action('wp_head', 'wp_generator');
add_action( 'init', 'register_menus' );
function register_menus() {
register_nav_menus(
array(
'main-nav' => 'Main Navigation',
'main-secondary-nav' => 'Main Secondary Navigation',
'main-tertiary-nav' => 'Main Tertiary Navigation',
'footer-nav' => 'Footer Navigation',
'sidebar-menu' => 'Sidebar Menu'
)
);
}
add_action( 'widgets_init', 'register_widgets' );
function register_widgets(){
register_sidebar( array(
'name' => __( 'Sidebar' ),
'id' => 'main-sidebar',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
//Page Slug Body Class
add_filter( 'body_class', 'add_slug_body_class' );
function add_slug_body_class( $classes )
{
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
// Get Facebook image for Open Graph meta tags
function get_fbimage() {
global $post;
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '', '' );
if ( has_post_thumbnail($post->ID)) {
$fbimage = $src[0];
} else {
global $post, $posts;
$fbimage = '';
if($post->post_content) {
$output = preg_match_all('/<img\s+[^>]*src="([^"]*)"[^>]*>/i',
$post->post_content, $matches);
if (count($matches[1]) > 0) {
$fbimage = $matches[1][0];
}
}
}
if (empty($fbimage)) {
$fbimage = get_stylesheet_directory_uri() . "/images/default-image.jpg";
}
return $fbimage;
}
// Get and trim excerpt for meta description
function my_excerpt($text, $excerpt)
{
if ($excerpt) return $excerpt;
$raw_excerpt = $text;
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(' ', $words);
$text = $text . $excerpt_more;
} else {
$text = implode(' ', $words);
}
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
// Split blog content into two sections
function splitParagraphs($string, $index) {
$string = get_content_with_formatting($string);
$paragraphs = explode("</p>", $string, 30);
$paragraphLength = count($paragraphs);
$halfWayPoint = floor(count($paragraphs) / 2);
$firstHalf = array();
$secondHalf = array();
if ($index == 1) {
for ($i = 0; $i < $halfWayPoint; $i++) {
array_push($firstHalf, $paragraphs[$i]);
}
$firstHalf = implode("", $firstHalf);
return $firstHalf;
}
else {
for ($i = $halfWayPoint; $i < $paragraphLength; $i++) {
array_push($secondHalf, $paragraphs[$i]);
}
$secondHalf = implode("", $secondHalf);
return $secondHalf;
}
}
// Include content formatting tags
function get_content_with_formatting($content){
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
// add svg mime type to uploads
function cc_mime_types( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
// strip shortcodes from excerpt
add_filter( 'the_excerpt', 'remove_media_credit_from_excerpt' );
function remove_media_credit_from_excerpt( $excerpt ) {
return preg_replace ('/\[media-credit[^\]]*\](.*)\[\/media-credit\]/', '$1', $excerpt);
}
function ic_display_ga_code()
{
$options = get_option('ic_theme_options');
$multiple_accounts = explode(",", $options['google_analytics']);
if (is_array($multiple_accounts)) {
$gaCode = "";
$domainTemplate = "
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type='text/javascript'>
var _gaq = _gaq || [];
var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', '%s']);
_gaq.push(['_setDomainName', 'invisiblechildren.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>
";
foreach ($multiple_accounts as $acct) {
$account_id = trim($acct);
$gaCode .= sprintf($domainTemplate, $account_id);
}
$gaCode .= "
<script type='text/javascript'>
(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';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
<!-- END GOOGLE ANALYTICS CODE -->
";
print $gaCode;
}
}