-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
443 lines (386 loc) · 13.5 KB
/
functions.php
File metadata and controls
443 lines (386 loc) · 13.5 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
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
<?php
/**
* LWTV functions and definitions
*
* @package LWTV Custom Theme
*/
// Versioning for efficient developers.
if ( ! defined( 'LWTV_THEME_VERSION' ) ) {
$versions = array();
// Automatically updated by the build script. Update ./package.json to change this.
$versions['lwtv-underscores'] = '6.5.6';
// Automatically updated by the build script.
$versions['bootstrap'] = '5.3.8';
// MANUAL. Bump when you update the dark mode css.
$versions['bootstrap_dark'] = '1.1.0';
// Automatically updated by the build script. Update ./plugins/lwtv-plugin/php/blocks/package.json to change this.
$versions['lwtv-blocks'] = '1.1.0';
define( 'LWTV_THEME_VERSION', $versions );
}
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 825; /* pixels */
}
/**
* LWTV Stuff
*/
// Theme constants These will be used for server and web paths.
// so we don't have to reference functions every time.
if ( ! defined( 'LWTV_THEME_PATH' ) ) {
define( 'LWTV_THEME_PATH', get_stylesheet_directory() );
}
if ( ! defined( 'LWTV_THEME_URL' ) ) {
define( 'LWTV_THEME_URL', trailingslashit( get_stylesheet_directory_uri() ) );
}
/**
* Get the title of the Posts page.
*/
function lwtv_theme_blog_page_title() {
if ( get_option( 'page_for_posts' ) ) {
return get_the_title( get_option( 'page_for_posts' ) );
}
}
/**
* Excerpts
*
* @param string $more set the more ellipsis.
*/
function lwtv_theme_excerpt_more( $more ) {
$more = '...';
return $more;
}
add_filter( 'excerpt_more', 'lwtv_theme_excerpt_more' );
/**
* Filter the except length to 20 words.
*
* @param int $length Excerpt length.
* @return int (Maybe) modified excerpt length.
*/
function lwtv_custom_excerpt_length( $length ) {
$length = 20;
return $length;
}
add_filter( 'excerpt_length', 'lwtv_custom_excerpt_length', 999 );
/**
* Widgets
*/
require_once 'inc/widgets/calendar-widget.php';
require_once 'inc/widgets/character-widget.php';
require_once 'inc/widgets/filter-top-widget.php';
require_once 'inc/widgets/filter-bottom-widget.php';
require_once 'inc/widgets/otd-widget.php';
require_once 'inc/widgets/show-widget.php';
require_once 'inc/widgets/social-nav-widget.php';
/**
* Images
*/
/*
* Custom Image Sizes
*
* character-img - Used on show and character pages
* show-img - Used as header image for shows
* postloop-img - Used in the post loop
* relatedshow-img - Used in the related shows section
* headshot-tiny - Used on relationships lists
* headshot-search - Used on SearchWP Live Search
*/
add_image_size( 'character-img', 350, 412, true );
add_image_size( 'show-img', 960, 400, true );
add_image_size( 'postloop-img', 525, 300, true );
add_image_size( 'relatedshow-img', 340, 150, true );
add_image_size( 'headshot-tiny', 50, 50, true );
add_image_size( 'headshot-search', 100, 100, true );
/**
* Comments
*/
require_once 'inc/walker-comment.php';
/**
* Authors
*
* Add bio box.
*/
if ( ! is_singular( 'post' ) ) {
require_once 'inc/author-box.php';
}
/**
* Archives
*
* @param string $title get rid of the “Category:”, “Tag:”, “Author:”, “Archives:”
* and “Other taxonomy name:” in the archive title.
*/
function lwtv_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'lwtv_archive_title' );
/**
* Theme Setup
*/
function lwtv_theme_add_editor_styles() {
add_editor_style( 'style.css' );
add_editor_style( 'custom-editor-style.css' );
}
add_action( 'admin_init', 'lwtv_theme_add_editor_styles' );
if ( ! function_exists( 'lwtv_theme_setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features. */
function lwtv_theme_setup() {
/**
* Set up Nav menus */
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'lwtv-underscores' ),
'social_menu' => __( 'Social Menu', 'lwtv-underscores' ),
)
);
/**
* 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' );
/* Add default posts and comments RSS feed links to head */
add_theme_support( 'automatic-feed-links' );
/* Enable support for Post Thumbnails on posts and pages */
add_theme_support( 'post-thumbnails' );
/* Enable support for a Theme Logo */
add_theme_support( 'custom-logo' );
/* 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' ) );
// Enable shortcodes in text widgets.
add_filter( 'widget_text', 'do_shortcode' );
// Enable editor styles.
add_theme_support( 'editor-styles' );
}
}
add_action( 'after_setup_theme', 'lwtv_theme_setup' );
/**
* Register widgetized areas and update sidebar with default widgets
*/
function lwtv_theme_widgets_init() {
// Home Sidebar.
register_sidebar(
array(
'name' => __( 'Home Page Sidebar', 'lwtv-underscores' ),
'id' => 'sidebar-1',
'description' => 'The sidebar for the home page',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Sub Page Sidebar.
register_sidebar(
array(
'name' => __( 'Sub Page Sidebar', 'lwtv-underscores' ),
'id' => 'sidebar-2',
'description' => 'The sidebar for sub pages',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Footer Widget 1.
register_sidebar(
array(
'name' => __( 'Footer Widget Area One', 'lwtv-underscores' ),
'id' => 'footer-1',
'description' => 'The first footer widget area.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Footer Widget 2.
register_sidebar(
array(
'name' => __( 'Footer Widget Area Two', 'lwtv-underscores' ),
'id' => 'footer-2',
'description' => 'The second footer widget area.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Footer Widget 3.
register_sidebar(
array(
'name' => __( 'Footer Widget Area Three', 'lwtv-underscores' ),
'id' => 'footer-3',
'description' => 'The third footer widget area.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Footer Widget 4.
register_sidebar(
array(
'name' => __( 'Footer Widget Area Four', 'lwtv-underscores' ),
'id' => 'footer-4',
'description' => 'The third footer widget area.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Credits Widget.
register_sidebar(
array(
'name' => __( 'Bottom Footer Widget Area', 'lwtv-underscores' ),
'id' => 'subfooter-1',
'description' => 'The bottom footer credits area.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Sidebar for Actor Archives.
register_sidebar(
array(
'name' => esc_html__( 'Sidebar - Actor Archives', 'lwtv-underscores' ),
'id' => 'archive-actor-sidebar',
'description' => esc_html__( 'This is the sidebar for actor archives.', 'lwtv-underscores' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Sidebar for Character Archives.
register_sidebar(
array(
'name' => esc_html__( 'Sidebar - Character Archives', 'lwtv-underscores' ),
'id' => 'archive-character-sidebar',
'description' => esc_html__( 'This is the sidebar for character archives.', 'lwtv-underscores' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
// Sidebar for Show Archives.
register_sidebar(
array(
'name' => esc_html__( 'Sidebar - Show Archives', 'lwtv-underscores' ),
'id' => 'archive-show-sidebar',
'description' => esc_html__( 'This is the sidebar for show archives.', 'lwtv-underscores' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'lwtv_theme_widgets_init' );
/**
* Bootstrap Stuff
*/
// Navigation Walker.
/**
* Register Custom Navigation Walker
*/
function register_navwalker() {
require_once 'inc/class-wp-bootstrap-5-navwalker.php';
}
add_action( 'after_setup_theme', 'register_navwalker' );
/*
* Pagination
* @usage
* 1) setup WP_Query with a $paged variable
* (https://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query)
* 2) Wherever you'd like the pagination to appear, add <?php echo page_navi( $query ); ?>
* where $query is the entire $query setup in the previous step
*/
require_once 'inc/wp_bootstrap_pagination.php';
// Add classes to “next_post_link” and “previous_post_link”.
add_filter( 'next_post_link', 'post_link_attributes' );
add_filter( 'previous_post_link', 'post_link_attributes' );
/**
* Pagination
*
* @param string $output add classes to links.
*/
function post_link_attributes( $output ) {
$code = 'class="page-link"';
return str_replace( '<a href=', '<a ' . $code . ' href=', $output );
}
add_filter( 'next_posts_link_attributes', 'posts_link_attributes' );
add_filter( 'previous_posts_link_attributes', 'posts_link_attributes' );
/**
* Pagination
*
* Add classes to pagination links
*/
function posts_link_attributes() {
return 'class="page-link"';
}
/**
* Scripts and styles
*/
function lwtv_theme_scripts() {
// combined + minified.
// navigation.js, skip-link-focus-fix.js, a11y.js, bootstrap-color-mode.
wp_enqueue_script( 'yikes-starter-navigation', get_template_directory_uri() . '/inc/js/yikes-theme-scripts.min.js', array(), LWTV_THEME_VERSION['lwtv-underscores'], true );
wp_enqueue_script( 'lwtv-dark-mode', get_template_directory_uri() . '/inc/js/bootstrap-color-mode.min.js', array(), LWTV_THEME_VERSION['bootstrap_dark'], false );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// Bootstrap
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/inc/bootstrap/css/bootstrap.min.css', array(), LWTV_THEME_VERSION['bootstrap'], 'all', false );
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/inc/bootstrap/js/bootstrap.bundle.min.js', array( 'jquery' ), LWTV_THEME_VERSION['bootstrap'], 'all', true );
// Fonts
wp_enqueue_style( 'open-sans', '//fonts.googleapis.com/css?family=Open+Sans:400,600,700', array(), LWTV_THEME_VERSION['lwtv-underscores'], false );
wp_enqueue_style( 'oswald', '//fonts.googleapis.com/css?family=Oswald:400,500', array(), LWTV_THEME_VERSION['lwtv-underscores'], false );
// This has to be at the bottom to override Bootstrap.
wp_enqueue_style( 'yikes-starter-style', get_stylesheet_directory_uri() . '/style.min.css', array(), LWTV_THEME_VERSION['lwtv-underscores'], false );
// Overlay JS.
if ( get_post_type( get_the_ID() ) === 'post_type_actors' ) {
wp_enqueue_script( 'lwtv-overlay', get_template_directory_uri() . '/inc/js/overlay-linkable.js', array( 'jquery' ), LWTV_THEME_VERSION['lwtv-underscores'], true );
}
}
add_action( 'wp_enqueue_scripts', 'lwtv_theme_scripts' );
/**
* Enqueue block styles in the editor.
*/
function lwtv_block_editor_styles() {
wp_enqueue_style( 'lwtv-block-editor', get_stylesheet_directory_uri() . '/style-editor.min.css', array(), LWTV_THEME_VERSION['lwtv-blocks'], true );
}
add_action( 'enqueue_block_editor_assets', 'lwtv_block_editor_styles' );
/* Custom template tags for this theme. */
require get_template_directory() . '/inc/template-tags.php';
/* Custom functions that act independently of the theme templates. */
require get_template_directory() . '/inc/extras.php';
/* Customizer additions. */
require get_template_directory() . '/inc/customizer.php';
/**
* Optional Items
*/
/* Implement the Custom Header feature. */
require get_template_directory() . '/inc/custom-header.php';
/* Remove custom background support */
remove_theme_support( 'custom-background' );
/**
* Special Lesbian Items
*/
require get_template_directory() . '/plugins/index.php';