0

I just want to put the CSS's content inside tag <style amp-custom>

This is my action inside function

function amp_template_add_styles() {
    $stylesheets = get_template_directory_uri() . '/material/public/app.min.css';
    echo file_get_contents( $stylesheets );
}
add_action( 'amp_template_css', 'amp_template_add_styles', 99 );

And i call the function insider tag <head>

<style amp-custom>
    <?php do_action( 'amp_template_css', 'amp_template_add_styles'); ?>
</style>

And this is the error when i implement in this way

enter image description here

There are anyone knows about this, please help me, thanks

  • why do you trying to include stylesheet in this way? cant you use enqueue method? – Vishwa May 8 at 4:35
  • Google AMP need to put CSS inside tag <style amp-custom> and if you use wp_enqueue_style, u can't put it inside <style amp-custom> – Hùng Phạm May 8 at 5:33
  • function amp_template_add_styles() { ob_start(); $stylesheets = file_get_contents(get_template_directory() . '/material/public/app.min.css'); ob_clean(); echo $stylesheets; } add_action( 'amp_template_css', 'amp_template_add_styles', 99 ); – Bhupen May 8 at 7:15
  • awesome, thank you so much – Hùng Phạm May 8 at 7:38
  • @Bhupen – Please consider adding a proper answer. – leymannx May 8 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.