Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only render SVGs on edit-post in admin
  • Loading branch information
Alex Lende committed Feb 17, 2022
commit 41080f467acd343005917d14711031ff0c96fc3c
12 changes: 12 additions & 0 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,18 @@ function wp_enqueue_global_styles() {
* @since 5.9.0
*/
function wp_global_styles_render_svg_filters() {
/*
* When calling via the in_admin_header action, we only want to render the
* SVGs on the post editor page.
*/
global $pagenow;
if (
is_admin() &&
( 'post.php' !== $pagenow || 'edit' !== $_GET['action'] )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also use is_admin() && get_current_screen()->is_block_editor() it should work for the site editor as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The site editor doesn't need the SVGs because it's rendering the editor in an iframe that doesn't have access to the filters rendered in the page.

WordPress/gutenberg#37727 is open to render the SVGs via JavaScript into that iframe.

Copy link
Author

@ajlende ajlende Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even so, I think get_current_screen()->is_block_editor() is still a better way of checking, so I've updated it.

There are a bunch of other checks that are happening with that method, so it's probably safer to use.

) {
return;
}

$filters = wp_get_global_styles_svg_filters();
if ( ! empty( $filters ) ) {
echo $filters;
Expand Down