-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
176 lines (149 loc) · 5.07 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
<?php
function wpskeleton_setup()
{
wpskeleton_load_theme_textdomain();
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style();
// This theme uses wp_nav_menu() in one location.
register_nav_menu( 'main', __( 'Main Menu', 'wpskeleton' ) );
}
add_action( 'after_setup_theme', 'wpskeleton_setup' );
/**
* Make themes available for translation.
* Translations can be added to the /languages/ directory of each theme.
* The textdomain used in a theme must match its ID.
*
* For example:
* In the theme wpskeleton, translations are called using __('My String', 'wpskeleton')
* and the translations are written in wp-content/themes/wpskeleton/languages/
*
* To translate your strings use the POT Generator plugin.
* It will generate and compile, for each locale activated in WPML:
* wp-content/themes/wpskeleton/languages/wpskeleton.pot
* wp-content/themes/wpskeleton/languages/fr_FR.po
* wp-content/themes/wpskeleton/languages/fr_FR.mo
*
* @uses load_theme_textdomain() For translation/localization support.
*/
function wpskeleton_load_theme_textdomain()
{
$theme = wp_get_theme();
do {
$textdomain = $theme->get_stylesheet();
load_theme_textdomain( $textdomain, $theme->get_stylesheet_directory() . '/languages' );
} while ($theme = $theme->parent());
}
/**
* Outputs HTML page title.
* Used in wp_head action
*/
function wpskeleton_page_title()
{
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;
// $title_settings = get_option('title_tagline');
$separator = '|';
$title = wp_title($separator, false, 'right');
// Add the blog name.
$title .= get_bloginfo('name');
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title .= " $separator $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
$title .= " $separator " . sprintf( __( 'Page %s', 'wpskeleton' ), max( $paged, $page ) );
$title = apply_filters('wpskeleton_page_title', $title);
$title = esc_html($title);
echo "<title>$title</title>\n";
}
add_action('wp_head', 'wpskeleton_page_title', 1);
/**
* Add meta elements to wp_head
* Metas must be array containing props => value.
* Ex:
* - array('charset' => 'utf-8')
* - array('name' => 'generator', 'content' => 'Wordpress')
*/
function wpskeleton_head_metas()
{
$metas = array();
$metas = apply_filters('wpskeleton_head_metas', $metas);
foreach ($metas as $meta) {
if (!empty($meta['ie'])) {
$ie_str = $meta['ie'] === true ? 'if IE' : $meta['ie'];
unset($meta['ie']);
echo "<!--[$ie_str]>";
h('meta', $meta, false);
echo "<![endif]-->\n";
} else {
h('meta', $meta, false);
echo PHP_EOL;
}
}
}
add_action('wp_head', 'wpskeleton_head_metas', 0);
/**
* @return string representing the content attribute in the meta viewport
*/
function wpskeleton_meta_viewport()
{
$viewport = array(
'width' => 'device-width',
);
$viewport = apply_filters('wpskeleton_meta_viewport', $viewport);
$content = array();
foreach ($viewport as $key => $value) {
$content[] = "$key=$value";
}
return implode(',', $content);
}
function wpskeleton_meta_defaults($metas)
{
// Remove some existing
remove_action('wp_head', 'noindex', 1);
remove_action('wp_head', 'wp_generator');
if (isset($GLOBALS['sitepress'])) {
remove_action('wp_head', array($GLOBALS['sitepress'], 'meta_generator_tag'));
}
$metas[] = array('charset' => get_bloginfo('charset'));
$metas[] = array('name' => 'viewport', 'content' => wpskeleton_meta_viewport());
if ('0' == get_option('blog_public')) {
$metas[] = array('name' => 'robots', 'content' => 'noindex,nofollow');
}
$metas[] = array('http-equiv' => "X-UA-Compatible", 'content' => "IE=edge", 'ie' => true);
return $metas;
}
add_filter('wpskeleton_head_metas', 'wpskeleton_meta_defaults', 0);
function wpskeleton_link_pingback()
{
h('link', array('rel' => 'pingback', 'href' => get_bloginfo('pingback_url')));
echo PHP_EOL;
}
add_action('wp_head', 'wpskeleton_link_pingback');
function wpskeleton_layout_classes($classes)
{
$layout = get_option('layout');
if ($layout && isset($layout['layout'])) {
switch ($layout['layout']) {
case 'left':
$classes[] = 'sidebar-left';
$classes[] = 'sidebar-one';
break;
case 'right':
$classes[] = 'sidebar-right';
$classes[] = 'sidebar-one';
break;
case 'none':
$classes[] = 'sidebar-none';
break;
case 'both':
$classes[] = 'sidebar-both';
break;
}
}
return $classes;
}
add_filter('body_class', 'wpskeleton_layout_classes');