themes-wordpress/blank-canvas-blocks/functions.php

65 lines
1.8 KiB
PHP
Raw Normal View History

<?php
if ( ! function_exists( 'blank_canvas_blocks_support' ) ) :
function blank_canvas_blocks_support() {
// Alignwide and alignfull classes in the block editor.
add_theme_support( 'align-wide' );
// Add support for experimental link color control.
add_theme_support( 'experimental-link-color' );
// Add support for responsive embedded content.
// https://github.com/WordPress/gutenberg/issues/26901
add_theme_support( 'responsive-embeds' );
// Add support for "reasonable default" block styles
add_theme_support( 'wp-block-styles');
// Add support for editor styles.
add_theme_support( 'editor-styles' );
// Enqueue editor styles.
add_editor_style( array(
blank_canvas_blocks_fonts_url(),
'/assets/ponyfill.css'
) );
}
add_action( 'after_setup_theme', 'blank_canvas_blocks_support' );
endif;
/**
*
* Enqueue scripts and styles.
*/
function blank_canvas_blocks_scripts() {
// Enqueue Google fonts
wp_enqueue_style( 'blank-canvas-blocks-fonts', blank_canvas_blocks_fonts_url(), array(), null );
wp_enqueue_style( 'blank_canvas_blocks-ponyfill', get_template_directory_uri() . '/assets/ponyfill.css', array(), wp_get_theme()->get( 'Version' ) );
}
add_action( 'wp_enqueue_scripts', 'blank_canvas_blocks_scripts', 11 );
/**
2021-03-12 15:15:10 +00:00
* Add Google webfonts
*
2021-03-12 15:15:10 +00:00
* @return $fonts_url
*/
2021-03-12 15:15:10 +00:00
function blank_canvas_blocks_fonts_url() {
$fonts_url = '';
2021-03-12 16:46:42 +00:00
$theme_data = WP_Theme_JSON_Resolver::get_merged_data()->get_settings();
$custom_data = $theme_data['defaults']['custom'];
if ( array_key_exists( 'fontsToLoadFromGoogle', $custom_data ) ) {
$font_families = $theme_data['defaults']['custom']['fontsToLoadFromGoogle'];
2021-03-12 15:15:10 +00:00
$font_families[] = 'display=swap';
2021-03-12 15:15:10 +00:00
// Make a single request for the theme fonts.
$fonts_url = 'https://fonts.googleapis.com/css2?' . implode( '&', $font_families );
}
return esc_url_raw( $fonts_url );
}