I need import css files from a folder in plugin directory to a plugin php file.
I tried
plugin_dir_path( __FILE__ );
<link rel="stylesheet" href="<?php echo __DIR__ . '/dahili/bootstrap.min.css'; ?>">
<link rel="stylesheet" href="./dahili/bootstrap.min.css">
but they gives wrong url.
for example, in my last trying, I get this adress:
/home/deniztas/hekim.deniz-tasarim.site/wp-content/plugins/my_post_plugin/widgets/dahili/bootstrap.min.css
but I need this:
hekim.deniz-tasarim.site/wp-content/plugins/my_post_plugin/widgets/dahili/bootstrap.min.css
how to get true address?
Note: Please dont close my question because of dublicate if you dont give 100% same question because I need real solution, I am not troll.
I need import css files from a folder in plugin directory to a plugin php file.
I tried
plugin_dir_path( __FILE__ );
<link rel="stylesheet" href="<?php echo __DIR__ . '/dahili/bootstrap.min.css'; ?>">
<link rel="stylesheet" href="./dahili/bootstrap.min.css">
but they gives wrong url.
for example, in my last trying, I get this adress:
http://www.hekim.deniz-tasarim.site/home/deniztas/hekim.deniz-tasarim.site/wp-content/plugins/my_post_plugin/widgets/dahili/bootstrap.min.css
but I need this:
hekim.deniz-tasarim.site/wp-content/plugins/my_post_plugin/widgets/dahili/bootstrap.min.css
how to get true address?
Share Improve this question asked Apr 13, 2020 at 16:26 Faruk rızaFaruk rıza 982 silver badges11 bronze badges 4Note: Please dont close my question because of dublicate if you dont give 100% same question because I need real solution, I am not troll.
- 1 Are you noting the difference between a file system "path" and URL? – jdm2112 Commented Apr 13, 2020 at 16:29
- @jdm2112 In fact, I didnt understood your comment.Can you please explain? – Faruk rıza Commented Apr 13, 2020 at 16:34
- 1 You're calling plugin_dir_path, which gets the filesystem path (starting with /home/). You want plugin_dir_url, which gets the base URL. Or other options on this question: How to link to images in my plugin regardless of the plugin folder's name – Rup Commented Apr 13, 2020 at 16:37
- @Rup thanks, it works now – Faruk rıza Commented Apr 13, 2020 at 17:16
1 Answer
Reset to default 1To solve this problem, we must use plugin_dir_url
command.
For example:
<?php
wp_register_style( 'foo-styles', plugin_dir_url( __FILE__ ) . 'dahili/bootstrap.min.css' );
wp_enqueue_style( 'foo-styles' );
?>