Created
June 6, 2018 03:16
-
-
Save inc2734/117b9af577d360667bf528c08248b827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function _set_preload_stylesheet( $tag, $handle, $src ) { | |
$handles = apply_filters( 'inc2734_wp_page_speed_optimization_output_head_styles', [] ); | |
if ( in_array( $handle, $handles ) && 0 === strpos( $src, home_url() ) ) { | |
$sitepath = site_url( '', 'relative' ); | |
$abspath = untrailingslashit( ABSPATH ); | |
if ( $sitepath ) { | |
$abspath = preg_replace( '|(.*?)' . preg_quote( $sitepath ) . '$|', '$1', $abspath ); | |
} | |
$parse = parse_url( $src ); | |
$buffer = \file_get_contents( $abspath . $parse['path'] ); | |
$buffer = str_replace( 'url(../', 'url(' . dirname( $parse['path'] ) . '/../', $buffer ); | |
$buffer = str_replace( 'url(//', 'url(/', $buffer ); | |
// @codingStandardsIgnoreStart | |
?> | |
<style><?php echo $buffer; ?></style> | |
<?php | |
// @codingStandardsIgnoreEnd | |
return; | |
} | |
$handles = apply_filters( 'inc2734_wp_page_speed_optimization_preload_stylesheets', [] ); | |
if ( in_array( $handle, $handles ) ) { | |
return str_replace( '\'stylesheet\'', '\'preload\' as="style"', $tag ); | |
} | |
return $tag; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment