每次我试图在函数.php文件中注册和排队脚本时,我都会收到错误
致命错误:允许的内存大小134217728字节已用完(已尝试分配261904字节)Foundation ''Apache2.2''htdocs''namewebsite''wp includes''class.wp-dependencies.php在线178
这是我的functions.php文件中使用的代码
function load_external_js() { // load external file
wp_enqueue_script('jquery');
wp_register_script('hash-change', get_template_directory_uri() . '/js/jquery.hashchange.event.plugin.js', array('hash-change'), '', true );
wp_enqueue_script('hash-change');
wp_register_script('ajax-theme', get_template_directory_uri() . '/js/ajax-implementation.js', array('ajax-theme'), '', true );
wp_enqueue_script('ajax-theme');
}
add_action('wp_enqueue_scripts', 'load_external_js');
我该怎么解决这个问题?
您需要脚本作为其自身的依赖项:
wp_register_script('hash-change', get_template_directory_uri() . '/js/jquery.hashchange.event.plugin.js', array('hash-change'), '', true );
wp_enqueue_script('hash-change');
将您对wp_register_script的调用更改为
wp_register_script('hash-change', get_template_directory_uri() . '/js/jquery.hashchange.event.plugin.js');
或者,如果您真的想需要另一个脚本作为依赖项,请注册该脚本并通过您给它的句柄重新使用它。
-
如果您可以访问PHP.ini文件,请更改PHP.ini中的行如果你的线路显示32M,试试64M。如果您的线路显示64M,请尝试128M
memory_limit = 64M
;一个脚本可能消耗的最大内存量(32MB) -
如果您没有访问
PHP.ini
的权限,请尝试将其添加到.htaccess
文件中:php_value memory_limit 64M -
尝试将此行添加到您的wp-config.php文件中:增加分配给PHP的内存
define('WP_MEMORY_LIMIT', '64M');
-
和你的主人谈谈。
在中找到:http://wordpress.org/support/topic/fatal-error-allowed-memory-size-6#post-1017842