From 27b4d57c4655fa43f4b858dc0308a68692bf2ff8 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 25 May 2020 21:26:36 +0100 Subject: [PATCH] Bugfix: only replace the first instance when inserting the estimated reading time --- modules/feature-readingtime.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/feature-readingtime.php b/modules/feature-readingtime.php index c8706a1..da23c87 100644 --- a/modules/feature-readingtime.php +++ b/modules/feature-readingtime.php @@ -23,11 +23,12 @@ register_module([ $insert = "{$reading_time[0]} minute read"; // TODO: Create a canonical way to insert something just below the header - this might be tough though 'cause the that isn't handled by the page_renderer though - $replace_count = 1; // Without a temp variable we get "only variables can be passed by reference", ref PHP 7.4.6 - $parts["{content}"] = str_replace( - "", "

$insert

", + $insert = "\n\t\t\t

$insert

"; + $parts["{content}"] = substr_replace( $parts["{content}"], - $replace_count + "$insert", + strpos($parts["{content}"], ""), + 5 ); }); }