简体   繁体   中英

Include JavaScript files to the document head with php

I'm creating a blog where I included header.php (Header, included in every page). Header contains a section where all the scripts (Scripts that will need in every pages) will be included.

header.php

<!DOCTYPE html>
  <html>
    <head>
      <!-- Scripts Section -->
      <script src="example01.js"></script>
      <script src="example02.js"></script>
      <title>Demo</title>
    </head>
    <body>
      <p>Blog</p>

But in a specific page, I've to include a specific script (file.js named).

index.php

<?php
  include('header.php');
  importjs('file.js'); /* Any Function To Import JavaScript*/
?>

If I include the JavaScript file here then it'll be included in body not the scripts section in the header. I don't know how to create that function. So please tell me how to create that function. create function in header.php and please first include the header before using function.

Thank You

I think, you should to write your line code like this example:

<?php int a; ?> 
<script type="text/javascript" src="file.js" /> 
<?php int b; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM