0

This is in the template file:

function add_pt_style() {
    wp_enqueue_style ('pt-style', ROOT_PATH.'/pt.css', array(), '1.0.0');
}
add_action( 'wp_enqueue_scripts', 'add_pt_style' );

get_header();

Here are my files:

enter image description here

Here is the error:

enter image description here

I cannot figure out why it's not found.

1 Answer 1

2

I don't think using ROOT_PATH is what you want to do here. That loads the server root.

try this code:

//add some pizazz
function pt_load_plugin_css () {
    
    $plugin_url = plugin_dir_url( __FILE__ );
    wp_enqueue_style ('pt-style', $plugin_url . 'css/pt.css', '1.0.0');
}
add_action ('wp_enqueue_scripts', 'pt_load_plugin_css');
3
  • plugin_dir_url( FILE ) gives me the child theme directory because this is in a template file, which is in the child theme dir Commented Feb 26, 2021 at 20:18
  • But you are right, if I move the enqueue to my plugin file, it works fine. I guess there's some problem with trying to do it from the template file. Not sure if I should mark answered or not. Commented Feb 26, 2021 at 20:21
  • ah. looking at your screenshot it looked like the whole project was a plugin. If you want to go another route let me know! let me know where the css (plugin?) and where the enqueue function is though!
    – rudtek
    Commented Feb 27, 2021 at 17:56

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.