如何从 WordPress 站点中的 html 访问目录中的文件?
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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>