php - 当我试图隐藏一个主题时,我的 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 中做同样的事情。到目前为止没有运气。如果有人可以帮助我,那就太好了。
解决方案
这是将脚本添加到 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/
推荐阅读
- python - Plotly 多行数据框
- asp.net-mvc-4 - 带有引导程序的 ASP.net 导航栏
- javascript - 事件发生后 localStorage 未重置为零
- python - 使用相同 Span 标签的表中的 Beautifulsoup 文本
- php - 使用 PHP 从 SQL Server 获取数组?
- python - 使用字典理解后更新字典值
- javascript - 仅从 foreach 循环接收最后一个 onclick 事件
- php - 无法在 React 中从我的 API 服务器获取数据
- matlab - 矩阵周期边界条件 Matlab
- python - 组合由循环产生的多个列表