-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
131 lines (109 loc) · 3.69 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
<?php
/* Enqueue scripts and styles */
function theme_name_scripts()
{
wp_enqueue_style('main-style', get_template_directory_uri() . '/css/style.min.css');
wp_enqueue_script('scrolling-nav', get_template_directory_uri() . '/js/scrolling-nav.js', array(), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'theme_name_scripts');
/* Disable WordPress Admin Bar for all users but admins. */
show_admin_bar(false);
/* Enable navigation */
add_action('after_setup_theme', 'register_my_menu');
function register_my_menu()
{
register_nav_menu('footer', __('Footer Menu', 'theme-slug'));
}
/* Enable support for the post thumbnails */
add_theme_support('post-thumbnails');
function myplugin_settings()
{
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action('init', 'myplugin_settings');
// Change the excerpt words size
function wp_trim_all_excerpt($text)
{
// Creates an excerpt if needed; and shortens the manual excerpt as well
global $post;
$raw_excerpt = $text;
if ('' == $text) {
$text = get_the_content('');
$text = strip_shortcodes($text);
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
}
$text = strip_tags($text, '<em><br><p>');
$excerpt_length = apply_filters('excerpt_length', 20);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words($text, $excerpt_length, $excerpt_more); //since wp3.3
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); //since wp3.3
}
// Multiple excerpts
function excerpt($limit)
{
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt) >= $limit) {
array_pop($excerpt);
$excerpt = implode(" ", $excerpt) . '...';
} else {
$excerpt = implode(" ", $excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
return $excerpt;
}
function content($limit)
{
$content = explode(' ', get_the_content(), $limit);
if (count($content) >= $limit) {
array_pop($content);
$content = implode(" ", $content) . '...';
} else {
$content = implode(" ", $content);
}
$content = preg_replace('/\[.+\]/', '', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
//Shorten the title of the events
function the_title_limit($length, $replacer = '...')
{
$string = the_title('', '', FALSE);
if (strlen($string) > $length)
$string = (preg_match('/^(.*)\W.*$/', substr($string, 0, $length + 1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
echo $string;
}
// Add thumbnail size for the events
add_image_size('events-thumb', 260, 125);
// Add thumbnail size for the news
add_image_size('news-thumb', 354, 166);
/* Theme settings page menu */
require_once('_inc/theme-settings.php');
require_once('_inc/custom-post-types.php');
require_once('_inc/custom-fields.php');
/* Meta description */
function create_meta_desc()
{
global $post;
if (!is_single()) {
return;
}
$meta = strip_tags($post->post_content);
$meta = strip_shortcodes($meta);
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
$meta = substr($meta, 0, 125);
echo "<meta name='description' content='$meta' />";
}
add_action('wp_head', 'create_meta_desc');
// Add menu order on posts
add_action( 'admin_init', 'posts_order_wpse_91866' );
function posts_order_wpse_91866()
{
add_post_type_support( 'post', 'page-attributes' );
}
?>