Website (editor) in Quirks mode because “var WPTB_CFG” before
-
Hi there,
version 2.0.7., both regular and PRO version. WordPress 6.8.1, Chrome, Windows 11. Sent you a message through your contact form on your website with the URL to the website on May, 22nd, didn’t get a reply though.
I believe as a follow-up to the “headers already sent error” topic, we now get a notice in the console (when in any editor), that Quirks mode is in effect, because the HTML does not start with
<!DOCTYPE html>(instead, the<script>holding thevar WPTB_CFGis there, before). Ends up bringing up possible rendering issues.Following the fix you and @ac2a worked out there, I checked the file as well and saw you still add the code for the
var WPTB_CFGwith a simpleecho.
I would suggest adding it with proper WordPress functions likewp_add_inline_script(), that solves the problem for me:In the function
public static function enqueue()(line 24) you call both functionsself::enqueue_config();andself::enqueue_i18n();after each other, right at the beginning. The first one echoes the JS-global, the second does some i18n. They are both always called, no dependencies.
So the easiest way to usewp_add_inline_script()for me was to swap the order of the two functions (callenqueue_i18n()first), and then in the second one,enqueue_config(), do not echo the global but add it as inline script at the beginning of the i18n JS file, that was added just before in theenqueue_i18n():// old direct echo, remove.
// echo '<script type="text/javascript">var WPTB_CFG = ' . json_encode($data) . ';</script>';
// new way to add JS global at the beginning of i18n file (inline).
// needs the i18n to be enqueued already, therefore swap enqueue-order in enqueue().
wp_add_inline_script(
'wptb-i18n',
'var WPTB_CFG = ' . json_encode($data) . ';',
'before'
);Follows the code example below the wp_add_inline_script() docs.
If you have another script that you always enqueue on the admin, you could maybe prepend it there instead of misusing the i18n file for holding the data. But still, this way no more quirks-mode and save as you always enqueue those two together.
The topic ‘Website (editor) in Quirks mode because “var WPTB_CFG” before’ is closed to new replies.