I've made a new template file for Wordpress constructing the elements of the page via PHP and Wordpress recognizes the template as such.

Then I wanted to include a CSS file for said template (same folder) and went with the standard:

<link rel="stylesheet" type="text/css" href="style.css">

but for some reason the PHP file does not load the linked CSS settings. if I add

<? include('style.css') ?>

the content of it gets printed onto the page, meaning the php file can read it. So why doesn't it load the CSS settings?

Thanks for any help

2 Answers 2


CSS links are relative to the current request URI, not your PHP file. Use an absolute path like:

<link rel="stylesheet" href="<?php bloginfo( 'template_url' ) ?>/themesubfolder/style.css" />

Add below code to your functions.php

    function add_script_and_style() {
      // for .css add 
       wp_enqueue_style('my-style', get_template_directory_uri() . '/my_style.css');

       // for .js add
       wp_enqueue_script( 'my-js', get_template_directory_uri() .'/filename.js', false );

    add_action( 'wp_enqueue_scripts', 'add_script_and_style' );

Extra Info: Wordpress standard way to do

wp_enqueue_style function for .css file

AND wp_enqueue_scripts function for .js script file.

Thank you

  • Please add an explanation to why the OP should do that. And BTW, that line will not work as it is only part of a working code, and the correct file is functions.php Apr 15, 2015 at 10:27
  • @Pieter Goosen yes functions.php typing mistake. And wp_enqueue_style is the standard way to add css style in a theme.
    – Dking
    Apr 15, 2015 at 12:14
  • That line alone won't do it. Should be in a function hooked to wp_enqueue_scripts :-) Apr 15, 2015 at 12:15
  • @PieterGoosen Before downvote you should check the code i gave. And wp_enqueue_scripts is for add .js script AND wp_enqueue_style for CSS . whatever please check my way. Thank you.
    – Dking
    Apr 15, 2015 at 12:18
  • Please see wp_enqueue_scripts Apr 15, 2015 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.