2020-08-04 21:44:03 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Child Theme Functions and definitions
|
|
|
|
*
|
|
|
|
* @link https://developer.wordpress.org/themes/basics/theme-functions/
|
|
|
|
*
|
|
|
|
* @package WordPress
|
2020-10-09 15:58:23 +00:00
|
|
|
* @subpackage Spearhead
|
2020-08-04 21:44:03 +00:00
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ! function_exists( 'spearhead_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 spearhead_setup() {
|
|
|
|
// Add support for editor styles.
|
2020-10-05 09:56:34 +00:00
|
|
|
add_theme_support( 'editor-styles' );
|
2020-08-04 21:44:03 +00:00
|
|
|
|
|
|
|
// Enqueue editor styles.
|
2020-10-08 18:00:56 +00:00
|
|
|
add_editor_style(
|
|
|
|
array(
|
|
|
|
spearhead_fonts_url(),
|
|
|
|
'variables.css',
|
|
|
|
'style.css',
|
|
|
|
)
|
|
|
|
);
|
2020-08-04 21:44:03 +00:00
|
|
|
|
|
|
|
// Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
|
|
|
|
add_theme_support(
|
|
|
|
'editor-font-sizes',
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => __( 'Tiny', 'spearhead' ),
|
|
|
|
'shortName' => __( 'XS', 'spearhead' ),
|
|
|
|
'size' => 14,
|
|
|
|
'slug' => 'xs',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Small', 'spearhead' ),
|
|
|
|
'shortName' => __( 'S', 'spearhead' ),
|
|
|
|
'size' => 16,
|
|
|
|
'slug' => 'small',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Medium', 'spearhead' ),
|
|
|
|
'shortName' => __( 'M', 'spearhead' ),
|
|
|
|
'size' => 20,
|
|
|
|
'slug' => 'medium',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Large', 'spearhead' ),
|
|
|
|
'shortName' => __( 'L', 'spearhead' ),
|
|
|
|
'size' => 24,
|
|
|
|
'slug' => 'large',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'XL', 'spearhead' ),
|
|
|
|
'shortName' => __( 'XL', 'spearhead' ),
|
|
|
|
'size' => 36,
|
|
|
|
'slug' => 'xl',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Huge', 'spearhead' ),
|
|
|
|
'shortName' => __( 'XXL', 'spearhead' ),
|
|
|
|
'size' => 48,
|
|
|
|
'slug' => 'huge',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Add child theme editor color pallete to match Sass-map variables in `_config-child-theme-deep.scss`.
|
|
|
|
add_theme_support(
|
|
|
|
'editor-color-palette',
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => __( 'Primary', 'spearhead' ),
|
|
|
|
'slug' => 'primary',
|
2020-08-10 18:02:22 +00:00
|
|
|
'color' => '#DB0042',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Foreground', 'spearhead' ),
|
|
|
|
'slug' => 'foreground',
|
2020-08-04 21:44:03 +00:00
|
|
|
'color' => '#000000',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Background', 'spearhead' ),
|
|
|
|
'slug' => 'background',
|
2020-08-10 18:02:22 +00:00
|
|
|
'color' => '#FFFFFF',
|
2020-08-04 21:44:03 +00:00
|
|
|
),
|
|
|
|
)
|
2020-10-08 18:00:56 +00:00
|
|
|
);
|
2021-02-15 11:31:33 +00:00
|
|
|
|
2020-10-09 14:43:50 +00:00
|
|
|
remove_filter( 'excerpt_more', 'seedlet_continue_reading_link' );
|
|
|
|
remove_filter( 'the_content_more_link', 'seedlet_continue_reading_link' );
|
2020-08-04 21:44:03 +00:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
add_action( 'after_setup_theme', 'spearhead_setup', 12 );
|
|
|
|
|
2021-02-15 11:31:33 +00:00
|
|
|
/**
|
|
|
|
* Filter the colors for Speahead
|
|
|
|
*/
|
|
|
|
function spearhead_colors() {
|
|
|
|
return array(
|
|
|
|
array( '--global--color-background', '#FFFFFF', __( 'Background Color', 'seedlet' ) ),
|
|
|
|
array( '--global--color-foreground', '#000000', __( 'Foreground Color', 'seedlet' ) ),
|
|
|
|
array( '--global--color-primary', '#DB0042', __( 'Primary Color', 'seedlet' ) ),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
add_filter( 'seedlet_colors', 'spearhead_colors' );
|
|
|
|
|
2020-08-04 21:44:03 +00:00
|
|
|
/**
|
|
|
|
* Filter the content_width in pixels, based on the child-theme's design and stylesheet.
|
|
|
|
*/
|
|
|
|
function spearhead_content_width() {
|
2020-10-22 12:10:54 +00:00
|
|
|
return 782;
|
2020-08-04 21:44:03 +00:00
|
|
|
}
|
|
|
|
add_filter( 'seedlet_content_width', 'spearhead_content_width' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue scripts and styles.
|
|
|
|
*/
|
|
|
|
function spearhead_scripts() {
|
2020-10-08 11:12:15 +00:00
|
|
|
// dequeue parent styles
|
|
|
|
wp_dequeue_style( 'seedlet-style-navigation' );
|
|
|
|
|
2020-08-04 21:44:03 +00:00
|
|
|
// enqueue Google fonts, if necessary
|
2020-10-08 18:00:56 +00:00
|
|
|
wp_enqueue_style( 'spearhead-fonts', spearhead_fonts_url(), array(), null );
|
2020-08-04 21:44:03 +00:00
|
|
|
|
|
|
|
// Child theme variables
|
2021-01-14 15:21:57 +00:00
|
|
|
wp_dequeue_style( 'seedlet-custom-color-overrides' );
|
2020-08-04 21:44:03 +00:00
|
|
|
wp_enqueue_style( 'spearhead-variables-style', get_stylesheet_directory_uri() . '/variables.css', array(), wp_get_theme()->get( 'Version' ) );
|
2021-02-11 19:10:00 +00:00
|
|
|
|
2021-02-18 10:17:16 +00:00
|
|
|
if ( false === get_theme_mod( 'color_darkmode_disable', false ) ) {
|
2021-02-11 19:10:00 +00:00
|
|
|
wp_enqueue_style( 'spearhead-variables-dark-style', get_stylesheet_directory_uri() . '/variables-dark.css', array(), wp_get_theme()->get( 'Version' ) );
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:21:57 +00:00
|
|
|
wp_enqueue_style( 'seedlet-custom-color-overrides' );
|
2020-08-04 21:44:03 +00:00
|
|
|
|
|
|
|
// enqueue child styles
|
2020-10-08 18:00:56 +00:00
|
|
|
wp_enqueue_style( 'spearhead-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
|
2020-10-08 11:12:15 +00:00
|
|
|
wp_enqueue_style( 'spearhead-navigation', get_stylesheet_directory_uri() . '/navigation.css', array(), wp_get_theme()->get( 'Version' ) );
|
2020-08-04 21:44:03 +00:00
|
|
|
|
|
|
|
// enqueue child RTL styles
|
|
|
|
wp_style_add_data( 'spearhead-style', 'rtl', 'replace' );
|
2020-10-08 11:12:15 +00:00
|
|
|
wp_style_add_data( 'spearhead-navigation', 'rtl', 'replace' );
|
2020-08-04 21:44:03 +00:00
|
|
|
}
|
|
|
|
add_action( 'wp_enqueue_scripts', 'spearhead_scripts', 11 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue Custom Cover Block Styles and Scripts
|
|
|
|
*/
|
|
|
|
function spearhead_block_extends() {
|
|
|
|
// Block Tweaks
|
2020-10-08 18:00:56 +00:00
|
|
|
wp_enqueue_script(
|
|
|
|
'spearhead-block-extends',
|
2020-08-04 21:44:03 +00:00
|
|
|
get_stylesheet_directory_uri() . '/assets/js/extend-blocks.js',
|
2020-10-05 09:54:13 +00:00
|
|
|
array( 'wp-blocks', 'wp-edit-post' ) // wp-edit-post is added to avoid a race condition when trying to unregister a style variation
|
2020-08-04 21:44:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
add_action( 'enqueue_block_assets', 'spearhead_block_extends' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add Google webfonts
|
|
|
|
*
|
2020-12-01 18:20:36 +00:00
|
|
|
* @return value
|
2020-08-04 21:44:03 +00:00
|
|
|
*/
|
2020-12-01 18:20:36 +00:00
|
|
|
function spearhead_fonts_url() {
|
2020-10-08 18:00:56 +00:00
|
|
|
$fonts_url = '';
|
2020-08-04 21:44:03 +00:00
|
|
|
|
|
|
|
$font_families = array();
|
2020-08-10 18:02:22 +00:00
|
|
|
$font_families[] = 'family=Libre+Franklin:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700';
|
|
|
|
$font_families[] = 'family=IBM+Plex+Mono:wght@400;700';
|
2020-08-04 21:44:03 +00:00
|
|
|
$font_families[] = 'display=swap';
|
|
|
|
|
2020-10-08 18:00:56 +00:00
|
|
|
// Make a single request for the theme fonts.
|
|
|
|
$fonts_url = 'https://fonts.googleapis.com/css2?' . implode( '&', $font_families );
|
2020-10-05 09:54:13 +00:00
|
|
|
|
2020-10-08 18:00:56 +00:00
|
|
|
return $fonts_url;
|
2020-08-04 21:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load extras
|
|
|
|
*/
|
2020-12-01 18:20:36 +00:00
|
|
|
function seedlet_entry_meta_header() {
|
2020-08-10 20:59:14 +00:00
|
|
|
// Hide author, post date, category and tag text for pages.
|
|
|
|
if ( 'post' === get_post_type() ) {
|
|
|
|
// Posted on
|
|
|
|
seedlet_posted_on();
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 09:54:13 +00:00
|
|
|
// require get_stylesheet_directory() . '/inc/custom-header.php';
|
2020-10-08 18:00:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Block Patterns.
|
|
|
|
*/
|
|
|
|
require get_stylesheet_directory() . '/inc/block-patterns.php';
|
2020-10-09 12:43:52 +00:00
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'body_class',
|
|
|
|
function( $classes ) {
|
|
|
|
$stickies = get_option( 'sticky_posts' );
|
|
|
|
|
2023-09-28 16:09:13 +00:00
|
|
|
if ( is_countable( $stickies ) && count( $stickies ) && is_home() ) {
|
2020-10-09 12:43:52 +00:00
|
|
|
return array_merge( $classes, array( 'has-sticky-post' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
);
|
2020-10-09 14:43:50 +00:00
|
|
|
|
2020-10-13 14:57:47 +00:00
|
|
|
/**
|
|
|
|
* Create the continue reading link.
|
2020-10-09 14:43:50 +00:00
|
|
|
*/
|
2020-10-13 14:57:47 +00:00
|
|
|
function spearhead_continue_reading_link( $more ) {
|
2020-10-09 14:43:50 +00:00
|
|
|
if ( ! is_admin() ) {
|
2020-10-13 14:57:47 +00:00
|
|
|
$more_link = spearhead_more_link();
|
2020-10-09 14:43:50 +00:00
|
|
|
|
2020-10-13 14:57:47 +00:00
|
|
|
return '<p>' . $more_link . '</p>';
|
2020-10-09 14:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-13 14:57:47 +00:00
|
|
|
/**
|
|
|
|
* Create a more link for use in both "Read more" and excerpt contexts.
|
|
|
|
*/
|
|
|
|
function spearhead_more_link() {
|
|
|
|
$more_text = sprintf(
|
|
|
|
/* translators: %s: Name of current post. */
|
|
|
|
wp_kses( __( 'More', 'spearhead' ), array( 'span' => array( 'class' => array() ) ) ),
|
|
|
|
the_title( '<span class="screen-reader-text">"', '"</span>', false )
|
|
|
|
);
|
|
|
|
|
|
|
|
return '<a class="more-link" href="' . esc_url( get_permalink() ) . '">' . $more_text . ' ' . seedlet_get_icon_svg( 'dropdown' ) . '</a>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this instead of the default WordPress ellipsis which is […].
|
|
|
|
*/
|
2020-12-07 18:21:48 +00:00
|
|
|
function spearhead_excerpt_more( $more ) {
|
2020-12-03 22:04:58 +00:00
|
|
|
if ( is_admin() ) {
|
|
|
|
return $more;
|
|
|
|
}
|
|
|
|
return '…';
|
2020-10-13 14:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function spearhead_the_excerpt( $excerpt ) {
|
2020-10-29 10:31:03 +00:00
|
|
|
|
|
|
|
$audio_block = '';
|
|
|
|
if ( has_block( 'audio' ) ) {
|
|
|
|
$post = get_post();
|
|
|
|
$blocks = parse_blocks( $post->post_content );
|
|
|
|
foreach ( $blocks as $block ) {
|
|
|
|
if ( 'core/audio' === $block['blockName'] ) {
|
2020-10-29 11:19:28 +00:00
|
|
|
$audio_block .= '<div class="excerpt-audio-block">' . wp_kses_post( $block['innerHTML'] ) . '</div>';
|
2020-10-29 10:31:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-13 14:57:47 +00:00
|
|
|
// For cases where the post excerpt is empty
|
|
|
|
// (but the post might have content)
|
|
|
|
if ( 0 === strlen( $excerpt ) ) {
|
2020-10-29 10:31:03 +00:00
|
|
|
return $excerpt . $audio_block;
|
2020-10-13 14:57:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 10:31:03 +00:00
|
|
|
return $excerpt . '<span class="excerpt-more-link">' . spearhead_more_link() . '</span>' . $audio_block;
|
2020-10-13 14:57:47 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 14:23:21 +00:00
|
|
|
/**
|
|
|
|
* Overwrite Seedlet's post navigation template tag.
|
|
|
|
*/
|
|
|
|
if ( ! function_exists( 'seedlet_the_post_navigation' ) ) :
|
|
|
|
function seedlet_the_post_navigation() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2020-10-09 14:43:50 +00:00
|
|
|
// Filter the excerpt more link
|
2020-10-13 14:57:47 +00:00
|
|
|
add_filter( 'excerpt_more', 'spearhead_excerpt_more' );
|
2020-10-09 14:43:50 +00:00
|
|
|
|
|
|
|
// Filter the content more link
|
|
|
|
add_filter( 'the_content_more_link', 'spearhead_continue_reading_link' );
|
2020-10-13 14:57:47 +00:00
|
|
|
|
|
|
|
// Filter the excerpt
|
|
|
|
add_filter( 'get_the_excerpt', 'spearhead_the_excerpt' );
|
2020-10-14 10:08:57 +00:00
|
|
|
|
|
|
|
/*
|
2020-10-13 14:25:01 +00:00
|
|
|
* Post footer meta
|
|
|
|
*/
|
|
|
|
|
2020-10-13 15:38:47 +00:00
|
|
|
if ( ! function_exists( 'seedlet_entry_meta_footer' ) ) :
|
2020-10-13 14:25:01 +00:00
|
|
|
/**
|
|
|
|
* Prints HTML with meta information for the categories, tags and comments.
|
|
|
|
*/
|
2020-10-13 15:38:47 +00:00
|
|
|
function seedlet_entry_meta_footer() {
|
2020-10-13 14:25:01 +00:00
|
|
|
|
2020-10-13 15:38:47 +00:00
|
|
|
seedlet_posted_on();
|
2020-10-13 14:25:01 +00:00
|
|
|
|
|
|
|
// Edit post link.
|
|
|
|
edit_post_link(
|
|
|
|
sprintf(
|
|
|
|
wp_kses(
|
|
|
|
/* translators: %s: Name of current post. Only visible to screen readers. */
|
2020-10-14 11:00:39 +00:00
|
|
|
__( 'Edit <span class="screen-reader-text">%s</span>', 'spearhead' ),
|
2020-10-13 14:25:01 +00:00
|
|
|
array(
|
|
|
|
'span' => array(
|
|
|
|
'class' => array(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
get_the_title()
|
|
|
|
),
|
|
|
|
'<span class="edit-link">',
|
|
|
|
'</span>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2020-10-13 15:38:47 +00:00
|
|
|
if ( ! function_exists( 'seedlet_posted_on' ) ) :
|
2020-10-13 14:25:01 +00:00
|
|
|
/**
|
|
|
|
* Prints HTML with meta information for the current post-date/time.
|
|
|
|
*/
|
2020-10-13 15:38:47 +00:00
|
|
|
function seedlet_posted_on() {
|
2020-10-13 14:25:01 +00:00
|
|
|
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
|
|
|
|
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
|
|
|
|
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$time_string = sprintf(
|
|
|
|
$time_string,
|
|
|
|
esc_attr( get_the_date( DATE_W3C ) ),
|
|
|
|
esc_html( get_the_date( 'M d Y' ) ),
|
|
|
|
esc_attr( get_the_modified_date( DATE_W3C ) ),
|
|
|
|
esc_html( get_the_modified_date() )
|
|
|
|
);
|
|
|
|
|
|
|
|
printf(
|
|
|
|
'<span class="posted-on"><a href="%1$s" rel="bookmark">%2$s</a></span>',
|
|
|
|
esc_url( get_permalink() ),
|
|
|
|
$time_string
|
|
|
|
);
|
|
|
|
}
|
|
|
|
endif;
|