首页 > 解决方案 > 当我试图隐藏一个主题时,我的 wordpress 网站上出现了这个内存错误

问题描述

我一直在尝试将 HTML 模板转换为 WordPress 主题,但是一旦我为 js 文件执行 wp_enqueue_scripts,我就会收到此内存错误

Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 262144 bytes) in C:\xampp\htdocs\bootstrap\wp-includes\option.php on line 58

Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0

这是整个代码

function addjs()
{
    

    

    wp_register_script('jquery' , get_template_directory_uri() . '/plugin-frameworks/jquery-3.2.1.min.js' ,array(),1,1,1);
    wp_enqueue_scripts('jquery');

    wp_register_script('bootstrap' , get_template_directory_uri() . '/plugin-frameworks/bootstrap.min.js' ,array(),1,1,1);
    wp_enqueue_scripts('bootstrap');

    wp_register_script('swiper' , get_template_directory_uri() . '/plugin-frameworks/swiper.js' ,array(),1,1,1);
    wp_enqueue_scripts('swiper');

    wp_register_script('scripts' , get_template_directory_uri() . '/common/scripts.js' ,array(),1,1,1);
    wp_enqueue_scripts('scripts');

    wp_register_script('custom' , get_template_directory_uri() . '/custom.js' ,array(),1,1,1);
    wp_enqueue_scripts('custom');


}


add_action('wp_enqueue_scripts', 'addjs');

当我删除 add_action('wp_enqueue_scripts', 'addjs'); 时主题有效。我已经尝试过诸如增加 Wordpress 内存限制 wp-config 之类的修复,并且我也尝试在 php.ini 中做同样的事情。到目前为止没有运气。如果有人可以帮助我,那就太好了。

标签: phphtmlwordpressxamppwordpress-theming

解决方案


这是将脚本添加到 WordPress 主题的正确方法

function regitser_scripts()
{

    wp_enqueue_script('give a name','Your script path',array(),'version',true); // true for showing it on the footer and vice versa


}


add_action('wp_enqueue_scripts','regitser_scripts');


wp_eqnueue_scripts 是内存背后的罪魁祸首。显然 wp_eqnueue_scripts 和 wp_eqnueue_script 之间存在巨大差异。并确保路径正确。我很久以前就找到了修复程序,但忘记发布了。我希望这是有帮助的。在此处阅读更多信息:https ://developer.wordpress.org/reference/functions/wp_enqueue_script/


推荐阅读