From 792e91cac58557d03a677227fed1fdbfae54fa02 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 7 Mar 2024 00:19:40 +0100 Subject: [PATCH] Add FICTIONEER_DEFER_SCRIPTS constant --- INSTALLATION.md | 1 + functions.php | 5 +++++ includes/functions/_theme_setup.php | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/INSTALLATION.md b/INSTALLATION.md index dc3762eb..63d860b0 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -1368,4 +1368,5 @@ define( 'CONSTANT_NAME', value ); | FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER | boolean | Whether to order updated stories based on the latest chapter added, excluding stories without chapters. Default `false`. | FICTIONEER_ENABLE_STORY_CHANGELOG | boolean | Whether changes to the story chapter list should be logged. Default `true`. | FICTIONEER_ENABLE_BROWSER_NOTES | boolean | Whether to inform visitors of missing browser features. Default `true`. +| FICTIONEER_DEFER_SCRIPTS | boolean | Whether to defer scripts or load them in the footer. Default `true`. | FICTIONEER_EXAMPLE_CHAPTER_ICONS | array | Collection of example Font Awesome icon class strings. diff --git a/functions.php b/functions.php index 1bb420fd..7e62233b 100644 --- a/functions.php +++ b/functions.php @@ -381,6 +381,11 @@ if ( ! defined( 'FICTIONEER_ENABLE_BROWSER_NOTES' ) ) { define( 'FICTIONEER_ENABLE_BROWSER_NOTES', true ); } +// Boolean: Defer scripts +if ( ! defined( 'FICTIONEER_DEFER_SCRIPTS' ) ) { + define( 'FICTIONEER_DEFER_SCRIPTS', true ); +} + /* * Arrays */ diff --git a/includes/functions/_theme_setup.php b/includes/functions/_theme_setup.php index f50cb726..2982f471 100644 --- a/includes/functions/_theme_setup.php +++ b/includes/functions/_theme_setup.php @@ -793,7 +793,8 @@ if ( ! function_exists( 'fictioneer_add_font_awesome' ) ) { function fictioneer_add_custom_scripts() { // Setup $post_type = get_post_type(); - $strategy = fictioneer_compare_wp_version( '6.3' ) ? array( 'strategy' => 'defer' ) : true; // Defer or load in footer + $strategy = fictioneer_compare_wp_version( '6.3' ) && FICTIONEER_DEFER_SCRIPTS + ? array( 'strategy' => 'defer' ) : true; // Defer or load in footer // Utility wp_register_script( 'fictioneer-utility-scripts', get_template_directory_uri() . '/js/utility.min.js', [], FICTIONEER_VERSION, $strategy );