gpt4 book ai didi

javascript - 如何在 WordPress 中加载 pdf Worker javascript

转载 作者:行者123 更新时间:2023-12-03 04:15:22 25 4
gpt4 key购买 nike

我必须在 WordPress 中显示 pdf 缩略图,并且我正在使用 pdfjs。我想在 javascript 中加载工作脚本,但我不明白如何在 javascript 代码中加载 pdf.workder.js 。因为我只知道 wp_enqueue_script 但不知道如何获取脚本路径。

PDFJS.workerSrc ="path/pdf.worker.js";

现在如何在 WordPress 运行时获取 javascript 中的路径。

最佳答案

将脚本放入主题目录中的文件夹中,其他js也应该在该文件夹中(以保持主题中的代码更清晰)并检索它只需使用:

get_template_directory_uri()

https://developer.wordpress.org/reference/functions/get_template_directory_uri/

或者:

get_template_directory()

如果您想要主题的绝对路径

https://developer.wordpress.org/reference/functions/get_template_directory_uri/

要获取插件的文件夹,请使用:

plugin_dir_path( 字符串 $file )

https://developer.wordpress.org/reference/functions/plugin_dir_path/

或者如果您想要 WP 主插件文件夹的路径,然后手动添加插件的路径,请使用:

plugins_url()

https://codex.wordpress.org/Function_Reference/plugins_url

关于javascript - 如何在 WordPress 中加载 pdf Worker javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44162218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com