woocommerce offtopic - Trying to link to a custom css file in a new folder

admin2025-06-02  3

I'm trying to link to a custom css file in a new folder of a small plugin I'm trying to make. I can't seem to get it to work. This is the line I have

echo '<link rel="stylesheet" href="' .  esc_url( plugins_url( 'public/css/front-end/uwc-tabs-style.css', __FILE__)) . '" >';

I've also tried the following but neither works.

echo '<link rel="stylesheet" href="' . plugins_url( 'public/css/front-end/uwc-tabs-style.css', __FILE__) . '" >';

As an edit. This is for an options result. eg. Select option 1 it returns the above stylesheet on the frontend

I'm trying to link to a custom css file in a new folder of a small plugin I'm trying to make. I can't seem to get it to work. This is the line I have

echo '<link rel="stylesheet" href="' .  esc_url( plugins_url( 'public/css/front-end/uwc-tabs-style.css', __FILE__)) . '" >';

I've also tried the following but neither works.

echo '<link rel="stylesheet" href="' . plugins_url( 'public/css/front-end/uwc-tabs-style.css', __FILE__) . '" >';

As an edit. This is for an options result. eg. Select option 1 it returns the above stylesheet on the frontend

Share Improve this question edited Feb 26, 2019 at 1:48 John Cook asked Feb 26, 2019 at 1:33 John CookJohn Cook 673 silver badges9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

I would use wp_enqueue_style() for this instead of echoing a <link>.

I worked it out. In case anyone else comes here looking for the answer here it is. I just had to add dirname(__FILE__) in place of __FILE__

echo '<link rel="stylesheet" href="' .  esc_url( plugins_url( 'public/css/front-end/uwc-tabs-style.css', dirname(__FILE__))) . '" >';
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748866802a314377.html

最新回复(0)