Web DevelopmentIncluding 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


  1. Retro Ladybug

    February 4, 2017 2:52 pm

    This was so helpful! Thank you!
  2. October 1, 2015 12:32 pm

    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 20, 2015 10:19 am

    it's not working. do you have any other way?
    1. September 20, 2015 5:51 pm

      @mashiru himuro what is not working ? do you have a code snippet ?
  4. ad

    July 1, 2014 2:29 pm

  5. May 1, 2011 5:47 am

    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.

Post a comment

Your email address will not be published. Required fields are marked *