最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

directory - Plugin path comes wrongly

programmeradmin1浏览0评论

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?

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.

Share Improve this question asked Apr 13, 2020 at 16:26 Faruk rızaFaruk rıza 982 silver badges11 bronze badges 4
  • 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
Add a comment  | 

1 Answer 1

Reset to default 1

To 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' );

?>
发布评论

评论列表(0)

  1. 暂无评论