duplication of inclusions when using function to improve wordpress loading
-
Hello
I created the function below to try to improve the loading of the site both for inclusions in functions and plugin style files, however after implementing it, I’m having duplicate includes.function add_async_to_css($html, $handle) { $async_loading = array( 'structured-content-frontend', ); if (in_array($handle, $async_loading)) { $async_html = str_replace(' href=', 'onload="this.onload=null;this.rel=\'stylesheet\'" href=', $html); $async_html .= str_replace(' rel="stylesheet"', ' rel="preload" as="style" ', $html); return $async_html; } return $html; } add_filter('style_loader_tag', 'add_async_to_css', 10, 2);Result of the inclusion
<link rel="stylesheet" id="structured-content-frontend-css" onload="this.onload=null;this.rel='stylesheet'" href="http://localhost:5002/wp-content/plugins/structured-content/dist/blocks.style.build.css?ver=1.5.0" media="all"> <link rel="stylesheet" id="structured-content-frontend-css" href="http://localhost:5002/wp-content/plugins/structured-content/dist/blocks.style.build.css?ver=1.5.0" media="all">Has anyone had a similar problem?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘duplication of inclusions when using function to improve wordpress loading’ is closed to new replies.