對於運行我的JS-應用程序,我需要在瀏覽器中的index.html至極打開包含許多鏈接樣式和其他腳本整合JS應用到WordPress插件
<script src="js/lib/jquery-2.1.1.min.js"></script>
<script src="js/lib/bootstrap.min.js"></script>
<script src="js/lib/bootstrap-select.min.js"></script>
我想要做的插件,多數民衆贊成將包裹我的js - 用於Wordpress。
<?php
/*
Plugin Name: Plugin
Description: Just plugin
Author: Me
Version: 1.0
*/
function showApp(){
$file = readfile("App/index.html", true);
echo $file;
}
add_action('init', 'showApp');
加載樣式和依賴JS文件時會發生問題。
UPDATE
<?php
/*
Plugin Name: Plugin
Description: Just plugin
Author: Me
Version: 1.0
*/
function showApp(){
$PATH = 'D:\xampp\htdocs\wp\wp-content\plugins\APP\js\app';
if (($_SERVER['REQUEST_URI']) == "/wp/2015/05/14/mypage/") {
if ($handle = opendir($PATH)) {
echo "Directory handle: $handle\n";
echo "Entries:\n";
while (false !== ($entry = readdir($handle))) {
echo "$entry\n";
enqueue_and_register_my_scripts($entry, $PATH);
}
closedir($handle);
$file = readfile('D:\xampp\htdocs\wp\wp-content\plugins\APP\index.html');
echo $file;
die();
}
}
}
function enqueue_and_register_my_scripts($script, $path){
wp_register_script($script, $path . $script);
wp_enqueue_script ($script, $path . $script);
}
add_action('init', 'showApp');
這沒有奏效。
你是這樣做的錯看樣本代碼,在插件加載/執行入隊所需的文件。並使用'add_action'來調用排列腳本的函數。然後在enqueue函數中,當需要使用'is_page()' – Musk
來調用這些文件時,您可以指定頁面。所有這些在[wordpress codex](https://codex.wordpress.org/Function_Reference/wp_enqueue_script ) – Danijel