-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
479 lines (373 loc) · 16.3 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<?php
/**
* Algori Blogger functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Algori_Blogger
*/
if ( ! function_exists( 'algori_blogger_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 algori_blogger_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Algori Blogger, use a find and replace
* to change 'algori-blogger' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'algori-blogger', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
/*
* Enable theme support for Post Formats.
*
* @link https://developer.wordpress.org/themes/functionality/post-formats/
*/
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ) );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'menu-1' => esc_html__( 'Primary', 'algori-blogger' ),
'menu-2' => esc_html__( 'Footer', 'algori-blogger' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support( 'custom-logo', array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
) );
/**
* Enable gutenberg block styles on the front-end.
*/
add_theme_support( 'wp-block-styles' );
/**
* Enable gutenberg wide alignment.
*/
add_theme_support( 'align-wide' );
/**
* Enable gutenberg responsive embeds.
*/
add_theme_support( 'responsive-embeds' );
/**
* Add custom link class navbar-brand to generated custom logo image link.
*/
add_filter('get_custom_logo', 'algori_blogger_change_logo_class');
function algori_blogger_change_logo_class ($html){
$html = str_replace('custom-logo-link', 'custom-logo-link navbar-brand', $html);
return $html;
}
/**
* Display custom logo image if uploaded otherwise show text logo.
*/
function algori_blogger_display_logo(){
if( function_exists('the_custom_logo') ){ // check if the_custom_logo() is supported i.e WP 4.5 and above
if( has_custom_logo() ){ // check if logo image has been set
the_custom_logo(); // display set logo image
}else{ // display text logo
// display H1 text logo if index page
if ( is_front_page() && is_home() ) {
echo '<h1 class="site-title"><a href="'; echo esc_url( home_url( '/' ) ); echo '" class="navbar-brand" rel="home">'; echo bloginfo( 'name' ); echo '</a></h1>';
} else { // display <p> text logo if not index page
echo '<p class="site-title"><strong><a href="'; echo esc_url( home_url( '/' ) ); echo '" class="navbar-brand" rel="home">'; echo bloginfo( 'name' ); echo '</a></strong></p>';
}
}
}
}
/**
* Display algori blogger custom comments format HTML Output.
*/
function algori_blogger_comments_format($comment, $args, $depth){
echo '<li '; comment_class('x'); echo' id="li-comment-'; comment_ID(); echo '">';
echo '<div class="user">';
echo get_avatar( $comment ) . '
</div>';
echo '<div class="message">
<div class="image-caption">
<div class="info">
<h2>';
/* Comment Author */
comment_author_link();
echo'</h2>
<div class="meta">
<div class="date">';/* Comment Date */
echo ' <a class="comment-permalink" href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">'; comment_date( 'j F Y' ); echo '</a>';
echo ' </div>
| ';
comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'])));
echo '</div>
</div>';
/* Comment Message */
$comment_message = __( 'Your comment is awaiting moderation.', 'algori-blogger' );
echo esc_html(($comment->comment_approved == '0')? $comment_message : comment_text());
echo '</div>
</div>';
}
/**
* Retrieves navigation to next/previous set of comments, when applicable.
*/
function algori_blogger_get_the_comments_navigation( $args = array() ) {
$navigation = '';
// Are there comments to navigate through?
if ( get_comment_pages_count() > 1 ) {
$args = wp_parse_args( $args, array(
'prev_text' => __( 'Older comments', 'algori-blogger' ),
'next_text' => __( 'Newer comments', 'algori-blogger' ),
'screen_reader_text' => __( 'Comments navigation', 'algori-blogger' ),
) );
$prev_link = get_previous_comments_link( $args['prev_text'] );
$next_link = get_next_comments_link( $args['next_text'] );
if ( $prev_link ) {
$navigation .= '<div class="nav-previous pull-right">' . $prev_link . '</div>';
}
if ( $next_link ) {
$navigation .= '<div class="nav-next pull-left">' . $next_link . '</div>';
}
$navigation .= '<div class="divide50"></div>';
$navigation = _navigation_markup( $navigation, 'comment-navigation', $args['screen_reader_text'] );
}
return $navigation;
}
/**
* Returns the navigation on single blog posts to next/previous set of posts, when applicable.
*/
function algori_blogger_get_the_single_posts_navigation( ) {
if($previous_link = get_previous_post()){ // Display previous post link if it exists
echo '<div class="navigation pull-left">';
$previous_btn_title = __( 'Previous', 'algori-blogger' );
previous_post_link('%link', $previous_btn_title, 'no');
echo '</div>';
}
if($next_link = get_next_post()){ // Display next post link if it exists
echo '<div class="navigation pull-right">';
$next_btn_title = __( 'Next', 'algori-blogger' );
next_post_link('%link', $next_btn_title, 'no');
echo '</div>';
}
}
/**
* Returns the navigation to next/previous set of posts, when applicable.
*/
function algori_blogger_get_the_posts_navigation( $args = array() ) {
$navigation = '';
// Don't print empty markup if there's only one page.
if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
$args = wp_parse_args( $args, array(
'prev_text' => __( 'Older posts', 'algori-blogger' ),
'next_text' => __( 'Newer posts', 'algori-blogger' ),
'screen_reader_text' => __( 'Posts navigation', 'algori-blogger' ),
) );
$next_link = get_previous_posts_link( $args['next_text'] );
$prev_link = get_next_posts_link( $args['prev_text'] );
if ( $prev_link ) {
$navigation .= '<div class="nav-previous pull-left">' . $prev_link . '</div>';
}
if ( $next_link ) {
$navigation .= '<div class="nav-next pull-right">' . $next_link . '</div>';
}
$navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'] );
}
return $navigation;
}
/**
* Implement editor styling, so as to make the TINYMCE editor content match the resulting post output in the theme, for a better user experience.
*/
add_editor_style(array('style/css/editor-style.css', 'http://fonts.googleapis.com/css?family=Raleway:400,300,500,600,700,800,900'));
add_theme_support( 'editor-styles' );
}
endif;
add_action( 'after_setup_theme', 'algori_blogger_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function algori_blogger_content_width() {
$GLOBALS['content_width'] = apply_filters( 'algori_blogger_content_width', 640 );
}
add_action( 'after_setup_theme', 'algori_blogger_content_width', 0 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function algori_blogger_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'algori-blogger' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'algori-blogger' ),
'before_widget' => '<section id="%1$s" class="sidebox widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'algori_blogger_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function algori_blogger_scripts() {
// Add CSS
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/style/css/bootstrap.css', array(), '20180131', 'all' );
wp_enqueue_style( 'owl-carousel', get_template_directory_uri() . '/style/css/owl.carousel.css', array(), '20180131', 'all' );
wp_enqueue_style( 'prettify', get_template_directory_uri() . '/style/js/google-code-prettify/prettify.css', array(), '20180131', 'all' );
wp_enqueue_style( 'algori-blogger-style', get_stylesheet_uri() );
wp_style_add_data( 'algori-blogger-style', 'rtl', 'replace' );
wp_enqueue_style( 'algori-blogger-blue', get_template_directory_uri() . '/style/css/color/blue.css', array(), '20180131', 'all' );
// Add Fonts
wp_enqueue_style( 'algori-blogger-google-fonts', 'http://fonts.googleapis.com/css?family=Raleway:400,300,500,600,700,800,900' );
wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/style/css/font-awesome.css', array(), '20180131', 'all' );
//Add JavaScript
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/style/js/bootstrap.min.js', array(), '20180131', true );
wp_enqueue_script( 'bootstrap-hover-dropdown', get_template_directory_uri() . '/style/js/bootstrap-hover-dropdown.min.js', array(), '20180131', true );
wp_enqueue_script( 'isotope', get_template_directory_uri() . '/style/js/jquery.isotope.min.js', array(), '20180131', true );
wp_enqueue_script( 'jquery-easytabs', get_template_directory_uri() . '/style/js/jquery.easytabs.min.js', array(), '20180131', true );
wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/style/js/owl.carousel.min.js', array(), '20180131', true );
wp_enqueue_script( 'jquery-fitvids', get_template_directory_uri() . '/style/js/jquery.fitvids.js', array(), '20180131', true );
wp_enqueue_script( 'jquery-sticky', get_template_directory_uri() . '/style/js/jquery.sticky.js', array(), '20180131', true );
wp_enqueue_script( 'prettify', get_template_directory_uri() . '/style/js/google-code-prettify/prettify.min.js', array(), '20180131', true );
wp_enqueue_script( 'jquery-slickforms', get_template_directory_uri() . '/style/js/jquery.slickforms.js', array(), '20180131', true );
wp_enqueue_script( 'retina', get_template_directory_uri() . '/style/js/retina.js', array(), '20180131', true );
wp_enqueue_script( 'algori-blogger-scripts', get_template_directory_uri() . '/style/js/scripts.js', array( 'jquery' ), '20190325', true );
wp_enqueue_script( 'algori-blogger-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
wp_enqueue_script( 'algori-blogger-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'algori_blogger_scripts' );
/**
* Enqueue fonts for gutenberg.
*/
function algori_blogger_block_editor_fonts(){
wp_enqueue_style( 'algori-blogger-block-editor-fonts', 'http://fonts.googleapis.com/css?family=Raleway:400,300,500,600,700,800,900' );
}
add_action( 'enqueue_block_editor_assets', 'algori_blogger_block_editor_fonts' );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
if ( defined( 'JETPACK__VERSION' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
/**
* Load recommended plugins with TGMPA.
*/
require get_parent_theme_file_path( '/inc/recommended-plugins.php' );
/**
* Customize Algori Blogger elipsis at the end of excerpts from " [...]" to just "..." .
*/
function algori_blogger_excerpt_more() {
if ( is_admin() ) { // avoid affecting admin dashboard
return $more;
}
return ' …';
}
add_filter('excerpt_more', 'algori_blogger_excerpt_more');
/**
* Customize Algori Blogger Search form input and submit button .
*/
function algori_blogger_get_search_form($form) {
$form = str_replace (
'<label>',
'<label style = "width: 100%">',
$form
);
$form = str_replace (
'search-submit',
'search-submit btn',
$form
);
return $form;
}
add_filter('get_search_form', 'algori_blogger_get_search_form');
/**
* Algori Blogger walker nav class.
*/
class Algori_Blogger_Walker_Nav_Primary extends Walker_Nav_menu {
function start_lvl( &$output, $depth = 0, $args = array() ){ //ul
$indent = str_repeat("\t",$depth);
$submenu = ($depth > 0) ? ' sub-menu' : '';
$output .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n";
}
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ){ //li a span
$indent = ( $depth ) ? str_repeat("\t",$depth) : '';
$li_attributes = '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = ($args->walker->has_children) ? 'dropdown' : '';
$classes[] = ($item->current || $item->current_item_ancestor) ? 'active' : '';
$classes[] = 'menu-item-' . $item->ID;
if( $depth && $args->walker->has_children ){
$classes[] = 'dropdown';
}
$active_menu = ($item->current || $item->current_item_ancestor) ? 'active' : '';
$class_names = ($depth > 0) ? ' class="dropdown-submenu '.$active_menu.'"' : ' class="dropdown '.$active_menu.'"';
$id = apply_filters('nav_menu_item_id', 'menu-item-'.$item->ID, $item, $args);
$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li' . $id . $value . $class_names . $li_attributes . '>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr($item->target) . '"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_url($item->url) . '"' : '';
$attributes .= ( $args->walker->has_children ) ? ' class="dropdown-toggle js-activated" ' : '';
$item_output = $args->before;
$item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= ( $depth == 0 && $args->walker->has_children ) ? ' </a>' : '</a>';
$item_output .= $args->after;
$output .= apply_filters ( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}