ampproject / ampproject/amp-wp

`data-amp-no-unwrap` effectiveness restricted to `<body>` element, disregarded in `<head>`

Open
#7,234 7 comments 0 reactions 0 assignees View on GitHub
Bug P2
Dominant language
PHP
Stars
1.8k
Forks
378
Avg merge
1d 15h
Merged PRs (30d)
10

Description

### Bug Description

`` elements with the `data-amp-no-unwrap` property in the `` are unwrapped regardless.

### Expected Behaviour

` /* This CSS applies only if JS is off. */ `

### Screenshots

In the body, there is this test code:
```html
JavaScript is off.

This page is served as AMP if this message shows up while JavaScript is on.
```
On a page served as AMP: https://anrghg.sunsite.fr/test-amp-compat/features/helpers/#127-amp-compatibility
On a non-AMP page: https://anrghg.sunsite.fr/publishing-helper/features/helpers/#127-amp-compatibility
(before the next heading).

In the head, there is this selector on both pages:
```css
.anrghg-display-toggle:not(:checked)+.anrghg-tocontents .anrghg-contents-list .anrghg-contents-heading:target
```
On the non-AMP page, it is wrapped into ``.
On the AMP page, it survives tree-shaking and is in the valid CSS because it is unwrapped.

The adverse effect on the AMP is that a TOC item shows up below the TOC label after clicking a heading number, then reloading the page, while JS is on.

### PHP Version

8.1

### Plugin Version

2.3.0

### AMP plugin template mode

Standard

### WordPress Version

6.0.1

### Site Health

https://anrghg.sunsite.fr/test-amp-compat/wp-content/uploads/sites/3/2022/08/site-health_2022-08-30T22500200.txt

### Gutenberg Version

-

### OS(s) Affected

Linux

### Browser(s) Affected

Brave

### Device(s) Affected

desktop

### Acceptance Criteria

_No response_

### Implementation Brief

_No response_

### QA Testing Instructions

_No response_

### Demo

_No response_

### Changelog Entry

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the discrepancy using the two linked AMP and non-AMP pages, then trace the existing handling of `noscript` and `data-amp-no-unwrap` in the document head. Done means the attribute is respected in the head as it is in the body, the CSS remains unwrapped only where intended, and the reported TOC behavior is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.