如何在 wordpress 中加载 pdf worker javascript
How to load pdf worker javascript in wordpress
我必须在 wordpress 中显示 pdf thumb,我正在使用 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( string $file )
https://developer.wordpress.org/reference/functions/plugin_dir_path/
或者,如果您只想将路径指向 WP 的主插件文件夹,然后手动将路径添加到您的插件,请使用:
plugins_url()
我必须在 wordpress 中显示 pdf thumb,我正在使用 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( string $file )
https://developer.wordpress.org/reference/functions/plugin_dir_path/
或者,如果您只想将路径指向 WP 的主插件文件夹,然后手动将路径添加到您的插件,请使用:
plugins_url()