【问题标题】:How to include a html file in wordpress plugin如何在 wordpress 插件中包含 html 文件
【发布时间】:2017-10-18 13:18:04
【问题描述】:

我正在创建我网站的首页作为 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 文件的正确方法。请让我知道执行此操作的正确方法。

【问题讨论】:

  • 如果你想在WordPress中使用html的输出,我建议你使用twig插件
  • 您检查过错误吗?
  • 警告:file_get_contents(/wp-content/plugins/plugin-searchForm/template/customPage.html):无法打开流:D:\home\site\wwwroot\ 中没有这样的文件或目录wp-content\plugins\plugin-searchForm\plugin-searchForm.php 在第 45 行我收到此错误。

标签: php wordpress


【解决方案1】:

试试这个:

function displayHTMLpage() {
    $asubHTML = file_get_contents(plugins_url('/myfile/test.php',__FILE__ ));
    echo $asubHTML;
}
  add_action('wp_enqueue_scripts', 'adsense_unblock_divs');

【讨论】:

  • 这个对兄弟没有帮助。
【解决方案2】:

当我删除文件夹“模板”并将 html 文件保存在插件主文件夹中时,它起作用了。 但我不明白为什么当它在另一个文件夹中时 wordpress 不读取 html 文件。 :( :(

【讨论】:

    【解决方案3】:

    我知道这个问题很老了,但是对于任何可能遇到这个问题的人,我很确定错误是以反斜杠开头的路径,在 Linux 中,他会从根目录 (/) 我假设.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-17
      • 2011-09-07
      • 1970-01-01
      • 2014-06-29
      • 2017-06-23
      • 2016-02-27
      • 2019-06-22
      • 2015-01-25
      相关资源
      最近更新 更多