繁体   English   中英

当我试图隐藏主题时,我的 wordpress 网站上出现此 memory 错误

[英]I have been getting this memory error on my wordpress website when I tried to covert a theme

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

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 memory 限制 wp-config 并且我也尝试在 php.ini 中做同样的事情。 到目前为止没有运气。 如果有人可以帮助我,那就太好了。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM