-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
163 lines (158 loc) · 6.08 KB
/
functions.php
File metadata and controls
163 lines (158 loc) · 6.08 KB
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
<?php
/**
* Theme setup.
*/
function tailpress_setup() {
add_theme_support( 'title-tag' );
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'portfolio' ),
)
);
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
add_theme_support( 'custom-logo' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'align-wide' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'editor-styles' );
add_editor_style( 'css/editor-style.css' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( "responsive-embeds" );
add_theme_support( "custom-header");
add_theme_support( "custom-background");
}
add_action( 'after_setup_theme', 'tailpress_setup' );
/**
* Enqueue theme assets.
*/
function tailpress_enqueue_scripts() {
$theme = wp_get_theme();
wp_enqueue_style( 'tailpress', tailpress_asset( 'css/app.css' ), array(), $theme->get( 'Version' ) );
wp_enqueue_script( 'tailpress', tailpress_asset( 'js/app.js' ), array(), $theme->get( 'Version' ) );
wp_enqueue_script( 'flowbite', 'https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.1/flowbite.min.js', true);
wp_enqueue_script( 'ionicons-min', 'https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js', true);
}
add_action( 'wp_enqueue_scripts', 'tailpress_enqueue_scripts' );
/**
* Get asset path.
*
* @param string $path Path to asset.
*
* @return string
*/
function tailpress_asset( $path ) {
if ( wp_get_environment_type() === 'production' ) {
return get_stylesheet_directory_uri() . '/' . $path;
}
return add_query_arg( 'time', time(), get_stylesheet_directory_uri() . '/' . $path );
}
// Return an alternate title, without prefix, for every type used in the get_the_archive_title().
// Return an alternate title, without prefix, for every type used in the get_the_archive_title().
add_filter('get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( 'Posted in category: ', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_year() ) {
$title = get_the_date( _x( 'Y', 'yearly archives date format', 'portfolio' ) );
} elseif ( is_month() ) {
$title = get_the_date( _x( 'F Y', 'monthly archives date format', 'portfolio' ) );
} elseif ( is_day() ) {
$title = get_the_date( _x( 'F j, Y', 'daily archives date format', 'portfolio' ) );
} elseif ( is_tax( 'post_format' ) ) {
if ( is_tax( 'post_format', 'post-format-aside' ) ) {
$title = _x( 'Asides', 'post format archive title', 'portfolio' );
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
$title = _x( 'Galleries', 'post format archive title', 'portfolio' );
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
$title = _x( 'Images', 'post format archive title', 'portfolio' );
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
$title = _x( 'Videos', 'post format archive title', 'portfolio' );
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
$title = _x( 'Quotes', 'post format archive title', 'portfolio' );
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
$title = _x( 'Links', 'post format archive title', 'portfolio' );
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
$title = _x( 'Statuses', 'post format archive title', 'portfolio' );
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
$title = _x( 'Audio', 'post format archive title', 'portfolio' );
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
$title = _x( 'Chats', 'post format archive title', 'portfolio' );
}
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
} else {
$title = __( 'Archives', 'portfolio' );
}
return $title;
});
/**
* Adds option 'li_class' to 'wp_nav_menu'.
*
* @param string $classes String of classes.
* @param mixed $item The current item.
* @param WP_Term $args Holds the nav menu arguments.
*
* @return array
*/
function tailpress_nav_menu_add_li_class( $classes, $item, $args, $depth ) {
if ( isset( $args->li_class ) ) {
$classes[] = $args->li_class;
}
if ( isset( $args->{"li_class_$depth"} ) ) {
$classes[] = $args->{"li_class_$depth"};
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'tailpress_nav_menu_add_li_class', 10, 4 );
/**
* Adds option 'submenu_class' to 'wp_nav_menu'.
*
* @param string $classes String of classes.
* @param mixed $item The current item.
* @param WP_Term $args Holds the nav menu arguments.
*
* @return array
*/
function tailpress_nav_menu_add_submenu_class( $classes, $args, $depth ) {
if ( isset( $args->submenu_class ) ) {
$classes[] = $args->submenu_class;
}
if ( isset( $args->{"submenu_class_$depth"} ) ) {
$classes[] = $args->{"submenu_class_$depth"};
}
return $classes;
}
add_filter( 'nav_menu_submenu_css_class', 'tailpress_nav_menu_add_submenu_class', 10, 3 );
//Remove css/script types
add_action('wp_loaded', 'prefix_output_buffer_start');
function prefix_output_buffer_start() {
ob_start("prefix_output_callback");
}
function prefix_output_callback($buffer) {
return preg_replace( "%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer );
}
/**
* Add .js script if "Enable threaded comments" is activated in Admin
* Codex: {@link https://developer.wordpress.org/reference/functions/wp_enqueue_script/}
*/
function wpse218049_enqueue_comments_reply() {
if( is_singular() && comments_open() && ( get_option( 'thread_comments' ) == 1) ) {
// Load comment-reply.js (into footer)
wp_enqueue_script( 'comment-reply', '/wp-includes/js/comment-reply.min.js', array(), false, true );
}
}
add_action( 'wp_enqueue_scripts', 'wpse218049_enqueue_comments_reply' );