如何从 WordPress 站点中的 html 访问目录中的文件?

发布于 2025-01-11 15:58:44 字数 826 浏览 0 评论 0原文

我正在尝试在 WordPress 中使用 ReactJS 组件。我正在关注本教程 -

https://jhinter。 medium.com/using-react-based-web-components-in-wordpress-f0d4097aca38

直到我卡在最后一部分:我添加了这个作为空页面的 html 自定义块:

<script src="/apps/csptest-component/direflowBundle.js"></script>
<csptest-component></csptest-component>

控制台打印出:

获取 http://www.adminprofi.com/apps/csptest- component/direflowBundle.js net::ERR_ABORTED 404(未找到)

我已使用 FTP 将文件放入根目录中名为 apps/csptest-component 的文件夹中wordpress站点目录下可以看到上传成功。我需要更改 src 指向的链接吗?任何帮助表示赞赏!

I am trying to use reactjs components in wordpress. I was following this tutorial -

https://jhinter.medium.com/using-react-based-web-components-in-wordpress-f0d4097aca38

Until I got stuck at the last part: I have added this as an html custom block to an empty page:

<script src="/apps/csptest-component/direflowBundle.js"></script>
<csptest-component></csptest-component>

The console prints out:

GET http://www.adminprofi.com/apps/csptest-component/direflowBundle.js net::ERR_ABORTED 404 (Not Found)

I have used FTP to put the file in a folder called apps/csptest-component in the root directory of the wordpress site and I can see that the upload was successful. Do I need to change the link that the src is pointing to? Any help is appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2025-01-18 15:58:44

WordPress 允许您访问 wp-content 目录中的文件,因此最佳实践是设置子主题,然后您可以将 javascript 上传到目录:wp-content/themes/child/js 并使用 http://www.adminprofi.com/wp-content/themes/child/js/direflowBundles.js

建议使用子主题以确保您的脚本在主题更新时不会被删除(有大量关于如何执行此操作的资源)。在这里创建一个名为 js 的文件夹以保持整洁。

编辑:我认为最简单的方法是将脚本上传到: /wp-content/themes/Divi/js 文件夹,然后您可以访问您的脚本,例如:

WordPress allows you to access files in the wp-content directory, so best practice would be to have a child theme setup and then you can upload your javascript to the directory: wp-content/themes/child/js and access it using http://www.adminprofi.com/wp-content/themes/child/js/direflowBundles.js .

It's recommended to use a child theme to ensure your script doesn't get removed when your theme is updated (plenty of resources on how to do this). Create a folder in here called js for tidiness.

EDIT: I think it will be easiest for you to upload your script to: /wp-content/themes/Divi/js folder, and then you can access your script like: <script src="http://www.adminprofi.com/wp-content/themes/Divi/js/yourscriptname.js"></script>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文