-
Notifications
You must be signed in to change notification settings - Fork 5
/
functions.php
199 lines (180 loc) · 5.48 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
<?php
/**
* Functions and definitions
*
* @package WordPress
* @subpackage Thunderblog
* @since 0.0.1
*/
if ( ! defined( 'THUNDERBLOG_VERSION' ) ) {
define( 'THUNDERBLOG_VERSION', '1.0.17' );
}
// enable theme support for featured images
add_theme_support( 'post-thumbnails' );
// enable Wordpress generated titles
add_theme_support( 'title-tag' );
// enable automatic RSS links in the header
add_theme_support( 'automatic-feed-links' );
// navigation menus for top and footer menu
function thunderblog_register_menus() {
register_nav_menus([
'primary' => __( 'Main Menu' ),
'footer' => __( 'Footer Menu' ),
]);
}
add_action( 'init', 'thunderblog_register_menus' );
// footer widgets for three columns
function thunderblog_register_footer_widgets() {
register_sidebar(
array(
'name' => __( 'Footer Column 1', 'thunderblog' ),
'id' => 'footer-1',
'description' => __( 'Appears on the first footer column.', 'thunderblog' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
)
);
register_sidebar(
array(
'name' => __( 'Footer Column 2', 'thunderblog' ),
'id' => 'footer-2',
'description' => __( 'Appears on the second footer column.', 'thunderblog' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
)
);
register_sidebar(
array(
'name' => __( 'Footer Column 3', 'thunderblog' ),
'id' => 'footer-3',
'description' => __( 'Appears on the third footer column.', 'thunderblog' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
)
);
}
add_action( 'widgets_init', 'thunderblog_register_footer_widgets', 20 );
// custom comment template
function thunderblog_comment ( $comment, $args, $depth ) {
?>
<div class="comment" id="comment-<?php comment_ID(); ?>">
<div class="avatar">
<?php if ( $args['avatar_size'] != 0 ) : ?>
<?php echo get_avatar( $comment, $args['avatar_size'] ); ?>
<?php endif; ?>
</div>
<h3 class="comment-meta">
<cite><?php echo get_comment_author(); ?></cite>
<?php _e( 'wrote on', 'thunderblog' ); ?>
<time>
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __( '%1$s at %2$s' ), get_comment_date(), get_comment_time() );
?>
</a>
</time>
<span class="ml-auto"><?php echo edit_comment_link( __( 'Edit', 'thunderblog' ) ); ?></span>
</h3>
<blockquote>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em><?php _e( 'Your comment is awaiting moderation.', 'thunderblog' ); ?></em>
<?php endif; ?>
<?php comment_text(); ?>
<?php
echo comment_reply_link(
array_merge(
$args,
array(
'depth' => $depth,
'max_depth' => $args['max_depth'],
)
)
);
?>
</blockquote>
<?php
}
// customize customizer to add theme options
function thunderblog_customize_register ( $wp_customize ) {
// custom download link
$wp_customize->add_setting( 'download_url' );
$wp_customize->add_control(
'download_url',
array(
'label' => __( 'Download URL' ),
'type' => 'url',
'section' => 'title_tagline',
)
);
// custom donation link
$wp_customize->add_setting( 'donation_url' );
$wp_customize->add_control(
'donation_url',
array(
'label' => __( 'Donation URL' ),
'type' => 'url',
'section' => 'title_tagline',
)
);
}
/**
* Adds the featured image (if any) to the (rss/atom/whatever) feed.
*
* @param string $text
*
* @return string
*/
function thunderblog_add_featured_image_to_feed( string $text ): string {
global $post;
// No featured image? Skip!
if ( ! has_post_thumbnail( $post ) ) {
return $text;
}
$featured_image = get_the_post_thumbnail( $post, [ 640, 360 ] );
return "<p>{$featured_image}</p>{$text}";
}
/**
* Echo's out a link entry containing the posts featured image, and caption if available.
* @return void
*/
function thunderblog_output_featured_image_as_link() {
global $post;
// No featured image? Skip!
if ( ! has_post_thumbnail( $post ) ) {
return;
}
$featured_image = get_the_post_thumbnail_url( $post );
$featured_caption = get_the_post_thumbnail_caption( $post ) ?? $post->post_title;
echo "<link rel='thumbnail' href='{$featured_image}' title='{$featured_caption}' />";
}
add_action( 'customize_register', 'thunderblog_customize_register' );
add_filter( 'the_content_feed', 'thunderblog_add_featured_image_to_feed' );
add_filter( 'atom_entry', 'thunderblog_output_featured_image_as_link' );
add_action( 'wp_enqueue_scripts', function () {
// load styles
wp_enqueue_style( 'normalize', get_template_directory_uri() . '/assets/normalize.css' );
wp_enqueue_style( 'style', get_stylesheet_uri(), [], THUNDERBLOG_VERSION );
// load scripts
wp_enqueue_script( 'script', get_template_directory_uri() . '/assets/main.js', [], THUNDERBLOG_VERSION, true );
wp_enqueue_script( 'scriptmodule', get_template_directory_uri() . '/assets/share-on-mastodon_v1.2.0.min.js', [], '1.2.0', true );
add_filter('script_loader_tag', 'add_type_module' , 10, 3);
} );
/**
* Serve a script as module
*/
function add_type_module($tag, $handle, $src) {
// if not your script, do nothing and return original $tag
if ( 'scriptmodule' !== $handle ) {
return $tag;
}
// change the script tag by adding type="module" and return it.
$tag = '<script type="module" src="' . esc_url( $src ) . '"></script>';
return $tag;
}