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
  1. May 1, 2011 at 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.

  2. ad
    July 1, 2014 at 2:29 PM


  3. mashiru himuro
    September 20, 2015 at 10:19 AM

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

    • September 20, 2015 at 5:51 PM

      @mashiru himuro

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

  4. October 1, 2015 at 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 .

  5. Retro Ladybug
    February 4, 2017 at 2:52 PM

    This was so helpful! Thank you!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: