Home > Web Development > Including external Javascript and CSS files in PHP

Including external Javascript and CSS files in PHP

Here is how to include external javascript and css files in your php code

   //include CSS Style Sheet
   echo "<link rel='stylesheet' type='text/css' href='path-to-css-file' />";

   //include a javascript file
   echo "<script type='text/javascript' src='path-to-javascript-file'></script>";

If you want to include the javascript and css source code inside the php file itself then you can do it like this

   //include CSS Style Sheet
   echo "<style type='text/css'>
         border: 1px solid;
         color: blue;

      /*heading class*/
      .heading1 {
         font size: 10px;

   //include a javascript file
   echo "<script type='text/javascript'>
      /* All your javascript code goes here*/
Categories: Web Development Tags:
  1. Retro Ladybug
    February 4th, 2017 at 14:52 | #1

    This was so helpful! Thank you!

  2. October 1st, 2015 at 12:32 | #2

    Thank for your this kind help. Php supports all css, javascript and html contents. Again thanks. Can you give me a tutorial about how to search data in php and mysql .

  3. mashiru himuro
    September 20th, 2015 at 10:19 | #3

    it’s not working. do you have any other way?

    • September 20th, 2015 at 17:51 | #4

      @mashiru himuro

      what is not working ? do you have a code snippet ?

  4. ad
    July 1st, 2014 at 14:29 | #5


  5. May 1st, 2011 at 05:47 | #6

    to load an external javascript file into the page use wp_enqueue_script() function and to add an external stylesheet file use wp_style_enqueue() function to load the file properly into wordpress.

  1. No trackbacks yet.