Make WordPress Core

Opened 14 months ago

Closed 14 months ago

Last modified 14 months ago

#59505 closed defect (bug) (fixed)

Fix HTML5 validation error for skip-link css on footer

Reported by: plugindevs's profile plugindevs Owned by: westonruter's profile westonruter
Milestone: 6.4 Priority: normal
Severity: normal Version: 5.9
Component: Themes Keywords: has-patch has-screenshots commit
Focuses: css Cc:

Description

Fix the following HTML5 validation error by moving skip-link CSS to head from the body:

Error: Element style not allowed as child of element body in this context. (Suppressing further errors from this subtree.)

Attachments (2)

skip-link-css-html5-validation-error.png (69.3 KB) - added by plugindevs 14 months ago.
Screenshot of the Error
59505.diff (1.4 KB) - added by sabernhardt 14 months ago.
moving skip link CSS/JS function to the wp_enqueue_scripts action

Download all attachments as: .zip

Change History (12)

@plugindevs
14 months ago

Screenshot of the Error

This ticket was mentioned in PR #5355 on WordPress/wordpress-develop by @plugindevs.


14 months ago
#1

Fix the following HTML5 validation error by moving skip-link CSS to head from the body:

Error: Element style not allowed as child of element body in this context. (Suppressing further errors from this subtree.)

Trac ticket: https://core.trac.wordpress.org/ticket/59505

@sabernhardt
14 months ago

moving skip link CSS/JS function to the wp_enqueue_scripts action

#2 @sabernhardt
14 months ago

  • Severity changed from critical to normal
  • Version changed from trunk to 5.9

Hi and thanks for the report!

If the function name should change, the old function would need to be moved to deprecated.php.

However, I think moving the CSS might be simpler now that the script is registered and enqueued instead of printing it all directly into the footer.

If my proof-of-concept patch is good, it probably should also have some documentation updates and backward compatibility code for anyone who removed the_block_template_skip_link from the wp_footer action. That includes the AMP plugin, WeCodeArt and emulsion themes, plus some others in a GitHub code search.

#4 @westonruter
14 months ago

Note that there are other instances where a style can appear in the body. Also, this is what print_late_styles() is for. See also https://github.com/WordPress/gutenberg/issues/38917

That being said, it makes sense to me that this should be moved from wp_footer to wp_enqueue_scripts, especially after #58775 and #58664.

@sabernhardt I've put your patch into a new PR and added the back-compat code: https://github.com/WordPress/wordpress-develop/pull/5472

cc @spacedmonkey

#5 @westonruter
14 months ago

With the back-compat code, a plugin can still do the following to remove the skip link:

<?php
remove_action( 'wp_footer', 'the_block_template_skip_link' );

#6 @westonruter
14 months ago

  • Milestone changed from Awaiting Review to 6.4

#7 @spacedmonkey
14 months ago

  • Keywords commit added
  • Owner changed from < plugindevs > to westonruter

This PR looks good. I like that is fixes an outstanding issue on gutenberg as well. Assigning to @westonruter to commit.

#8 @westonruter
14 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 56932:

Script Loader: Enqueue inline style for block template skip link in head instead of footer.

  • Introduce wp_enqueue_block_template_skip_link() to replace the_block_template_skip_link(). Add to wp_enqueue_scripts action instead of wp_footer.
  • Keep inline script for skip link in footer.
  • Restore original the_block_template_skip_link() from 6.3 and move to deprecated.php.
  • Preserve back-compat for unhooking skip-link by removing the_block_template_skip_link from wp_footer action.

Follow-up to [56682] and [56687].

Props sabernhardt, plugindevs, westonruter, spacedmonkey.
Fixes #59505.
See #58775.
See #58664.

@westonruter commented on PR #5472:


14 months ago
#9

Committed in r56932.

This ticket was mentioned in Slack in #core-performance by westonruter. View the logs.


14 months ago

Note: See TracTickets for help on using tickets.