php - Put css into head but css is part of an imported file -


webpagetest.org tells me

http://mypage.com/howitworks has css in document body: link node http://mypage.com/design_header.css should moved document head. 

this design_header.css stylesheet of header.php imported in body e.g.

<body>  <?php include 'header_login.php'; ?> </body> 

is there can this?

i guess might tell you need decent php templating system views (smarty?).

but, if you're looking quick solution, try leverage output buffering needs:

<?php // @ top of parent page  function move_css_to_head($buffer) {     // dom manipulation here achieve goal     $dom = new domdocument;     $dom->loadhtml($buffer);      $head = $dom->getelementsbytagname('head')->item(0);     $body = $dom->getelementsbytagname('body')->item(0);     $css_elms = $body->getelementsbytagname('link');      foreach ($css_elms $elm)         {         $head->appendchild($elm->clonenode());         $body->removechild($elm);         }      return $dom->savehtml(); }  ob_start('move_css_to_head'); // buffer response output, , call assigned function upon flushing ?>  <!-- regular page content -->  <?php // @ bottom of parent page, flush buffer ob_end_flush(); ?> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -