对于运行我的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