feat(new): insert code at the start of the body tag#391
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a third “site insertion” location by supporting WordPress’s wp_body_open hook so HTML snippets can be output at the start of the <body> tag.
Changes:
- Added a new snippet scope/location for body-start insertion (
body-content) and wired it towp_body_open. - Extended scope lists/icons/names across PHP + TS so the new location is selectable and validated.
- Updated Playwright E2E helpers/tests to cover the new body-start location.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/e2e/helpers/constants.ts | Adds SITE_BODY location constant for E2E location selection. |
| tests/e2e/code-snippets-evaluation.spec.ts | Adds E2E coverage for body-start HTML insertion. |
| src/php/Utils/i18n.php | Adds translation strings for new body-start scopes. |
| src/php/snippet-ops.php | Ensures active-snippet cache invalidation includes body-content. |
| src/php/Model/Snippet.php | Adds new scopes to the allowed scope list + icons + display names. |
| src/php/Integration/Evaluate_Content.php | Hooks wp_body_open and prints body-content snippets. |
| src/js/types/Snippet.ts | Extends TS scope unions to include new body-start scopes. |
| src/js/components/EditMenu/SnippetForm/fields/SnippetLocationInput.tsx | Exposes body-start location in the snippet editor location picker. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
How well supported is |
|
Thank you @rami-elementor . I needed this for one of my tasks :D |
|
@sheabunge All 3 functions relies on the theme author.
WordPress 5.2.0 was released on May 2019, over 7 years ago. I think that after 7 years it's safe to assume that this function is widely used. |
Currently the plugin supports 2 locations:
However, WordPress supports 3 locations:
<head>tag)<body>tag)<body>tag)This PR aims to add support for
wp_body_opento code-snippets. To allow users the ability to insert code at the start of the<body>tag.In pro: