2017-05-24 23 views
0

我必須在wordpress中顯示pdf thumb,並使用pdfjs。我想在JavaScript中加載工作者腳本,但我不明白如何在JavaScript代碼中加載pdf.workder.js。因爲我只知道wp_enqueue_script但不知道如何獲得腳本路徑。如何在wordpress中加載pdf工作者javascript

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

現在如何在運行時在WordPress可以在javascript路徑。

回答

1

把腳本主題目錄中,其中還包括其他的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()

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

+0

我使用的插件將使用相同的功能? – owaishanif786

+0

有一個函數用於直接檢索給定插件的路徑,在答案中添加 – quirimmo

相關問題