Skip to content

Instantly share code, notes, and snippets.

@peterwilsoncc
Last active January 21, 2018 08:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterwilsoncc/33b67ace4a3e7571af9af99b76649e5e to your computer and use it in GitHub Desktop.
Save peterwilsoncc/33b67ace4a3e7571af9af99b76649e5e to your computer and use it in GitHub Desktop.
<?php
/**
* Register assets required by the theme.
*/
function pwcc_register_assets() {
wp_register_style(
'pwcc-styles',
get_stylesheet_uri(),
array(),
'1.0'
);
wp_style_add_data( 'pwcc-styles', 'pwcc_h2_push', true );
}
add_action( 'wp', 'pwcc_register_assets' );
/**
* Add HTTP Link headers required by server push.
*/
function pwcc_server_push() {
global $wp_styles;
foreach ( $wp_styles->registered as $style ) {
if ( ! empty( $style->extra ) && $style->extra['pwcc_h2_push'] ) {
header( 'Link: <' . esc_url_raw( $style->src ) . '>; rel=preload; as=style' );
pwcc_style_cached( $style->handle );
}
}
var_dump( $wp_styles );
}
add_action( 'wp','pwcc_server_push', 20 );
@RaminMT
Copy link

RaminMT commented Jan 21, 2018

Hi,
Excuses where is "pwcc_style_cached" func? and why "var_dump"? :-D

tnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment