【问题标题】:Local Wordpress site receiving error when I add wp_head(); and wp_footer();当我添加 wp_head(); 时,本地 Wordpress 站点接收错误;和 wp_footer();
【发布时间】:2014-02-04 05:43:11
【问题描述】:

我在本地 Wordpress 网站上工作,当我添加 wp_head();和 wp_footer();函数到我的 index.php 文件中,该站点收到“无法加载网页,因为服务器未发送数据”消息。我的 htdocs 中有所有必需的 Wordpress 文件,并且我正在使用 MAMP。当我删除 wp_head();和 wp_footer();网站显示备份的功能。这是什么原因造成的?

<!DOCTYPE html>
<html>
  <head>
    <title><?php bloginfo('name'); ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <?php wp_head();?>
  </head>
  <body>
    <a class="btn" href="#">hello</a>

    <?php wp_footer()
  </body>
</html>

/**
 * Load CSS and Javascript
 */

function load_styles_and_scripts(){

    //load styles
    wp_enqueue_style(
            'bootstrap-styles',
            get_template_directory_uri() . '/css/bootstrap.min.css'
        );
    wp_enqueue_style(
            'main-styles',
            get_template_directory_uri() . '/style.css'
        );

    //load scripts
    wp_enqueue_scripts(
            'jquery',
            'http://code.jquery.com/jquery.min.js'
        );

    wp_enqueue_scripts(
            'bootstrap-scripts',
            get_template_directory_uri() . '/js/bootstrap.min.js'
        );


}

add_action('wp_enqueue_scripts', 'load_styles_and_scripts');

【问题讨论】:

  • 您的错误日志中有任何内容吗?一方面,您没有结束或关闭&lt;?php wp_footer()(它缺少;?&gt;
  • 不,Chrome 的控制台中没有任何内容。我修复了页脚功能,这不是问题。
  • 对不起,我不清楚 - 我的意思是你的服务器日志。您可能必须启用它们。我从未使用过 MAMP,但 this link 似乎可以解释它。也可能值得启用WordPress debugging

标签: php wordpress localhost


【解决方案1】:

在您的load_styles_and_scripts() 函数中,加载函数应为wp_enqueue_script

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-06
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    • 2011-02-20
    • 2017-02-22
    相关资源
    最近更新 更多