Yearly Date Archives Being Mishandled
-
The display of yearly date archives (Yoast SEO > Advanced > Date archives > Enable date archives) has a minor but irritating and performance-impacting bug. In creating the SEO Title for the browser tab, while handling a yearly archive URI (/?m=2024), the code insists on searching for month – with a zero index because only the year is present in the URI. This results is up to 4 warning messages of the type: PHP Warning: Undefined array key “00” in wp-includes/class-wp-locale.php on line 321 – in the debug.log file if you have WordPress error logging switched on. The displayed SEO Title text is just 0 rather than Year 2024, but the archive page itself displays correctly. The display of monthly archives (/?m=202402) works fine and the SEO Title is correct.
I brought this to the attention of Yoast Support but the friendly response bot (or not-so-friendly support person?) did not answer intelligently and said I should post to this forum – because we are not premium users.
I spent a lot of time searching the plugin code for where the ‘year, no month’ situation was being mishandled – without success. So I have adopted the ‘disgraceful’ bodge of altering the relevant WordPress core file at line 321 (wp-includes/class-wp-locale.php) with an appropriate if statement:
if (zeroise( $month_number, 2 ) != ’00’) return $this->month[ zeroise( $month_number, 2 ) ];
That stops all the “undefined array key” messages and the page displays correctly, though the SEO Title in the browser tab remains incorrect.
It would be great if someone was able to say where in the Yoast SEO code this bug is being caused. And, everyone, pester Yoast SEO to correct it! There also seems to be something to be said for WordPress checking for month and day-of-week numbers being in the correct range.
- You must be logged in to reply to this topic.