Split up head meta function

This commit is contained in:
Tetrakern 2024-02-07 23:24:46 +01:00
parent 6a6a624321
commit 21fed199cb
3 changed files with 49 additions and 34 deletions

View File

@ -265,7 +265,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `wp_dashboard_setup` | `fictioneer_remove_dashboard_widgets`
| `wp_default_scripts` | `fictioneer_remove_jquery_migrate`
| `wp_enqueue_scripts` | `fictioneer_add_custom_scripts`, `fictioneer_customizer_queue`, `fictioneer_style_queue`
| `wp_head` | `fictioneer_output_head_seo`, `fictioneer_output_rss`, `fictioneer_output_schemas`, `fictioneer_add_fiction_css`
| `wp_head` | `fictioneer_output_head_seo`, `fictioneer_output_rss`, `fictioneer_output_schemas`, `fictioneer_add_fiction_css`, `fictioneer_output_head_fonts`
| `wp_update_nav_menu` | `fictioneer_purge_nav_menu_transients`
<br>

View File

@ -48,7 +48,7 @@ if ( is_archive() || is_search() || is_404() ) {
<head>
<?php
// Includes charset, content type, viewport, fonts, etc...
// Includes charset, content type, viewport, etc...
fictioneer_output_head_meta();
// Prevent indexing if required

View File

@ -1045,7 +1045,7 @@ if ( ! function_exists( 'fictioneer_output_head_meta' ) ) {
* Output HTML <head> meta
*
* @since 5.0.0
* @since 5.10.0 - Refactor for font manager.
* @since 5.10.0 - Split up for font manager.
*/
function fictioneer_output_head_meta() {
@ -1057,41 +1057,56 @@ if ( ! function_exists( 'fictioneer_output_head_meta' ) ) {
<meta name="format-detection" content="telephone=no">
<meta name="theme-color" content="<?php echo '#' . get_background_color(); ?>">
<meta name="referrer" content="strict-origin-when-cross-origin">
<?php fictioneer_output_critical_fonts(); ?>
<?php // <--- End HTML
// Bundled fonts
$bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css';
// Create file if it does not exist
if ( ! file_exists( $bundled_fonts ) ) {
fictioneer_build_bundled_fonts();
}
// Output font stylesheets...
if ( file_exists( $bundled_fonts ) ) {
// ... base and custom
$base_fonts_href = get_template_directory_uri() . '/css/fonts-base.css?ver=' . FICTIONEER_VERSION;
$custom_fonts_href = get_template_directory_uri() . '/cache/bundled-fonts.css?ver=' . FICTIONEER_VERSION;
// Start HTML ---> ?>
<link rel="stylesheet" id="base-fonts-stylesheet" href="<?php echo $base_fonts_href; ?>" media="print" onload="this.media='all'; this.onload = null;">
<noscript><link rel="stylesheet" href="<?php echo $base_fonts_href; ?>"></noscript>
<link rel="stylesheet" id="bundled-fonts-stylesheet" href="<?php echo $custom_fonts_href; ?>" media="print" onload="this.media='all'; this.onload = null;">
<noscript><link rel="stylesheet" href="<?php echo $custom_fonts_href; ?>"></noscript>
<?php // <--- End HTML
} else {
// ... all theme fonts if something goes wrong
$full_fonts_href = get_template_directory_uri() . '/css/fonts-full.css?ver=' . FICTIONEER_VERSION;
// Start HTML ---> ?>
<link rel="stylesheet" href="<?php echo $full_fonts_href; ?>" media="print" onload="this.media='all'; this.onload = null;">
<noscript><link rel="stylesheet" href="<?php echo $full_fonts_href; ?>"></noscript>
<?php // <--- End HTML
}
}
}
// =============================================================================
// OUTPUT HEAD FONTS
// =============================================================================
/**
* Output font stylesheets <head> meta
*
* @since 5.10.0
*/
function fictioneer_output_head_fonts() {
// Critical path fonts
fictioneer_output_critical_fonts();
// Bundled fonts
$bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css';
// Create file if it does not exist
if ( ! file_exists( $bundled_fonts ) ) {
fictioneer_build_bundled_fonts();
}
// Output font stylesheets...
if ( file_exists( $bundled_fonts ) ) {
// ... base and custom
$base_fonts_href = get_template_directory_uri() . '/css/fonts-base.css?ver=' . FICTIONEER_VERSION;
$custom_fonts_href = get_template_directory_uri() . '/cache/bundled-fonts.css?ver=' . FICTIONEER_VERSION;
// Start HTML ---> ?>
<link rel="stylesheet" id="base-fonts-stylesheet" href="<?php echo $base_fonts_href; ?>" media="print" onload="this.media='all'; this.onload = null;">
<noscript><link rel="stylesheet" href="<?php echo $base_fonts_href; ?>"></noscript>
<link rel="stylesheet" id="bundled-fonts-stylesheet" href="<?php echo $custom_fonts_href; ?>" media="print" onload="this.media='all'; this.onload = null;">
<noscript><link rel="stylesheet" href="<?php echo $custom_fonts_href; ?>"></noscript>
<?php // <--- End HTML
} else {
// ... all theme fonts if something goes wrong
$full_fonts_href = get_template_directory_uri() . '/css/fonts-full.css?ver=' . FICTIONEER_VERSION;
// Start HTML ---> ?>
<link rel="stylesheet" href="<?php echo $full_fonts_href; ?>" media="print" onload="this.media='all'; this.onload = null;">
<noscript><link rel="stylesheet" href="<?php echo $full_fonts_href; ?>"></noscript>
<?php // <--- End HTML
}
}
add_action( 'wp_head', 'fictioneer_output_head_fonts', 5 );
// =============================================================================
// MODIFY ROBOTS META
// =============================================================================