Skip to content

Commit 45525b3

Browse files
committed
fix conditionally adding skipLink
1 parent 175a08f commit 45525b3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/full-site-editing/templates.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,16 @@ function gutenberg_the_skip_link() {
188188
return;
189189
}
190190

191-
// Early exit if not an FSE theme.
191+
// Early exit if not a block theme.
192192
if ( ! gutenberg_supports_block_templates() ) {
193193
return;
194194
}
195+
196+
// Early exit if not a block template.
197+
global $_wp_current_template_content;
198+
if ( ! $_wp_current_template_content ) {
199+
return;
200+
}
195201
?>
196202

197203
<?php
@@ -249,7 +255,12 @@ function gutenberg_the_skip_link() {
249255

250256
// Get the site wrapper.
251257
// The skip-link will be injected in the beginning of it.
252-
parentEl = document.querySelector( '.wp-site-blocks' ) || document.body,
258+
parentEl = document.querySelector( '.wp-site-blocks' );
259+
260+
// Early exit if the root element was not found.
261+
if ( ! parentEl ) {
262+
return;
263+
}
253264

254265
// Get the skip-link target's ID, and generate one if it doesn't exist.
255266
skipLinkTargetID = skipLinkTarget.id;

0 commit comments

Comments
 (0)