-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
227 lines (194 loc) · 7.44 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
<?php
function theme_setup() {
// Menus
register_nav_menu( 'main', 'Main Menu' );
// RSS Feed
add_theme_support( 'automatic-feed-links' );
// Thumbnails
add_theme_support( 'post-thumbnails' );
add_image_size( 'thumb', 150, 150, true ); // Normal thumbnail size
add_image_size( 'large-thumb', 300, 300, true ); // Large thumbnail size
add_image_size( 'featured-img', 740, 420, true ); // Featured Image size
add_image_size( 'background-img', 1400, 700, true ); // Featured Image size
}
add_action( 'after_setup_theme', 'theme_setup' );
// Enqueue styles
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'main', get_stylesheet_directory_uri().'/css/main.css', false, filemtime( get_stylesheet_directory() . '/style.css' ) );
wp_enqueue_style( 'style', get_stylesheet_directory_uri().'/style.css', false, filemtime( get_stylesheet_directory() . '/style.css' ) );
}
// Enqueue scripts
add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' );
function theme_enqueue_scripts() {
wp_deregister_script( 'jquery' ); // Deregister to put jQuery into footer
wp_register_script( 'jquery', get_stylesheet_directory_uri().'/js/jquery.min.js', false, NULL, true );
wp_enqueue_script( 'jquery' ); // Re-register jQuery
wp_enqueue_script( 'modernizr', get_stylesheet_directory_uri().'/js/application.min.js', 'jquery', NULL, true );
wp_enqueue_script( 'theme-functions', get_stylesheet_directory_uri().'/js/functions.js', 'jquery', NULL , true );
}
// Disable Emoji Loading
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
// Disable WP Embed
function my_deregister_scripts() {
wp_dequeue_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );
// Options Page
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => true,
'menu_position' => 20,
));
acf_add_options_sub_page(array(
'page_title' => 'Theme Settings',
'menu_title' => 'Settings',
'parent_slug' => 'theme-general-settings',
));
}
// Excerpt Length
function excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'excerpt_length');
// Read More after excerpt
function new_excerpt_more($more) {
global $post;
return '';
}
add_filter('excerpt_more', 'new_excerpt_more');
// Get ID from Page Name
function ID_from_page_name($page_name)
{
global $wpdb;
$page_name_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."'");
return $page_name_id;
}
// Pagination
function numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="pagination"><ul>' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li class="prev">%s</li>' . "\n", get_previous_posts_link('< Previous Page') );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li class="next">%s</li>' . "\n", get_next_posts_link('Next Page >') );
echo '</ul></div>' . "\n";
}
// This stuff fixes the pagination issue with custom posts.
function remove_page_from_query_string($query_string)
{
if ($query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
// 'page' in the query_string looks like '/2', so i'm spliting it out
list($delim, $page_index) = split('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
// Remove Menu Items
function remove_menus(){
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'tools.php' ); //Tools
}
add_action( 'admin_menu', 'remove_menus' );
add_action('nav_menu_css_class', 'add_current_nav_class', 10, 2 );
function add_current_nav_class($classes, $item) {
// Getting the current post details
global $post;
// Getting the post type of the current post
$current_post_type = get_post_type_object(get_post_type($post->ID));
$current_post_type_slug = $current_post_type->rewrite[slug];
// Getting the URL of the menu item
$menu_slug = strtolower(trim($item->url));
// If the menu item URL contains the current post types slug add the current-menu-item class
if (strpos($menu_slug,$current_post_type_slug) !== false) {
$classes[] = 'current-menu-item';
}
// Return the corrected set of classes to be added to the menu item
return $classes;
}
// is_tree
function is_tree( $pid ) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
if ( is_page($pid) )
return TRUE; // we're at the page or at a sub page
$anc = get_post_ancestors( $post->ID );
foreach ( $anc as $ancestor ) {
if( is_page() && $ancestor == $pid ) {
return TRUE;
}
}
return FALSE; // we aren't at the page, and the page is not an ancestor
}
// ACF Blocks
add_action('acf/init', 'my_acf_blocks_init');
function my_acf_blocks_init() {
// Check function exists.
if( function_exists('acf_register_block_type') ) {
acf_register_block_type(array(
'name' => 'button',
'title' => __('Button'),
'description' => __('A button to place in the content.'),
'render_template' => 'inc/block/button.php',
'enqueue_style' => get_template_directory_uri() . '/css/main.css',
'icon' => 'media-code',
'keywords' => array( 'button', 'link' ),
));
acf_register_block_type(array(
'name' => 'profile',
'title' => __('Profile'),
'description' => __('Add in team profile'),
'render_template' => 'inc/block/profile.php',
'enqueue_style' => get_template_directory_uri() . '/css/main.css',
'icon' => 'admin-users',
'keywords' => array( 'profile', 'team' ),
));
}
}
?>