我正在为我的网站创建一个首页作为一个wordpress插件。我想包括一个HTML文件也在我的插件。我使用下面的方法将html内容添加到我的插件中。
在wp版本4.8中:-
function displayHTMLpage() {
include( '\template\customPage.html' );
}
add_action( 'wp_enqueue_scripts', 'displayHTMLpage' );
在wp版本4.8.1中:-
function displayHTMLpage() {
$pageHTML = file_get_contents( plugins_url( '\template\customPage.html', __FILE__ ) );
echo $pageHTML;
}
add_action('wp_enqueue_scripts', 'displayHTMLpage');
现在,上述方法在4.8.2中不起作用。在我升级到这个最新版本后,html文件无法加载到网站中。我真的不确定在wordpress插件中包含HTML文件的正确方法。请告诉我做这件事的正确方法。
发布于 2017-10-18 13:52:36
试试这个:
function displayHTMLpage() {
$asubHTML = file_get_contents(plugins_url('/myfile/test.php',__FILE__ ));
echo $asubHTML;
}
add_action('wp_enqueue_scripts', 'adsense_unblock_divs');
发布于 2017-10-18 17:03:28
当我移除文件夹"template“并将html文件保存在插件主文件夹中时,它就起作用了。但是我不明白为什么当html文件在另一个文件夹里的时候wordpress不能读取它。:( :(
发布于 2018-01-29 16:35:39
我知道这个问题很老了,但是对于可能遇到这个问题的任何人来说,我非常确定错误是以反斜杠开头的路径,在Linux中,我假设他会从根目录(/)开始路径。
https://stackoverflow.com/questions/46811155
复制相似问题