-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
86 lines (67 loc) · 2.43 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
<?php
/*
|------------------------------------------------------------------
| Bootstraping a Theme
|------------------------------------------------------------------
|
| This file is responsible for bootstrapping your theme. Autoloads
| composer packages, checks compatibility and loads theme files.
|
*/
/*------------------------------------
* Composer Include
* ---------------------------------*/
if ( file_exists( $composer = __DIR__ . '/vendor/autoload.php' ) ) {
require $composer;
}
use MrBasirnia\App\Setup\Clab_Setup;
use MrBasirnia\App\Helpers\Clab_Helper;
/*------------------------------------
* Set Theme Constant
* ---------------------------------*/
Clab_Helper::define( 'CLAB__PATH', get_template_directory() . DIRECTORY_SEPARATOR );
Clab_Helper::define( 'CLAB__URL', get_template_directory_uri() . DIRECTORY_SEPARATOR );
/*------------------------------------
* Init Theme Setup
* ---------------------------------*/
Clab_Setup::getInstance();
/*------------------------------------
* Add Class To pagination
* ---------------------------------*/
add_filter( 'next_posts_link_attributes', 'posts_link_attributes' );
add_filter( 'previous_posts_link_attributes', 'posts_link_attributes' );
function posts_link_attributes(): string {
return 'class="btn btn-dark" style=" align-items: center; display: flex;"';
}
/*--------------------------------------------------
* Adding a class to the category description tag.
* -----------------------------------------------*/
add_filter( 'category_description', function ( $description, $category ) {
/* Trimming the description to 40 words and adding ... to the end of it. */
$des = wp_trim_words(
$description,
40,
'...'
);
/**
* Checking if the description is empty or not.
* If it is not empty, it will return the description with the class lead text-muted.
*/
if ( '' !== $description ) {
return "<p class='lead text-muted'>{$des}</p>";
}
return ''; //If description is empty, it will return an empty string.
}, 10, 2 );
/*--------------------------------------------------
* Add separator to category list.
* -----------------------------------------------*/
add_filter( 'clab_category_separator', function ( array $categories, string $separator = '/' ) {
$last_key = end( array_keys( $categories ) );
foreach ( $categories as $key => $category ) {
if ( $key === $last_key ) {
continue;
}
$category->name .= " {$separator}";
}
return $categories;
} );