How to fix this error?


  • | 475 points

    I’m using windows 10, 64-bit,
    Local server: laragon
    All steps since starting going ok, till reached to add some code in the file: functions.php

    <?php

    function load_css()
    {

    wp_register_style(‘bootstrap’, get_template_directory_uri(). ‘/css/bootstrap.min.css’, array(), false, ‘all’ );
    wp_enqueue_style(‘bootstrap’);

    }
    add_action(‘wp_enqueue_scripts’, ‘load_css’);

    function load_js()
    {
    wp_enqueue_scripts(‘jquery’);
    wp_register_script(‘bootstrap’, get_template_directory_uri() . ‘/js/bootstrap.min.js’, ‘jquery’, false, true);
    wp_enqueue_script(‘bootstrap’);
    }
    add_action(‘wp_enqueue_scripts’, ‘load_js’);

    When loaded the main (home page) this result was displayed:
    ———————-
    Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) in C:\laragon\www\test\wp-includes\cache.php on line 544

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

    Please help how to solve this issue,
    Thanks,


  • | 1683 points

    You can try to increase the memory limit by right-clicking the Laragon icon in the system tray. Then on the menu pick PHP / Quick settings / memory_limit. When you click on the memory_limit menu item you will get a popup where you can type in a number to increase it.


  • | 475 points

    @dmccan
    I have increased and doubled all values,, but still seeing the error like this:
    Fatal error: Allowed memory size of 3145728000 bytes exhausted (tried to allocate 20480 bytes) in C:\laragon\www\test\wp-includes\class-wp-hook.php on line 281
    There has been a critical error on your website.

    this error happened when I typed the code in functions.php file:

    <?php

    function load_css()
    {

    wp_register_style('bootstrap', get_template_directory_uri(). '/css/bootstrap.min.css', array(), false, 'all' );
    wp_enqueue_style('bootstrap');

    }
    add_action('wp_enqueue_scripts', 'load_css');

    function load_js()
    {
    wp_enqueue_scripts('jquery');
    wp_register_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', 'jquery', false, true);
    wp_enqueue_script('bootstrap');
    }
    add_action('wp_enqueue_scripts', 'load_js');

    ======


  • administrators
    | 118581 points

    @almadar: I believe you have a memory leak in your code. Please check your code.


  • | 1683 points

    wp_enqueue also registers, so you don't need both functions. You would use the register function separately when you want to conditionally equeue it later, but since you are doing it immediately after then it is not needed.

    Also, I don't thing you need to enqueue jquery. I think that is already done by WordPress. I didn't test this, but something along these lines:

    wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css', array(), null, 'all' );
    wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), false, true );

    Here is an example loading bootstrap from the CDN
    https://sridharkatakam.com/load-bootstrap-wordpress/

    You can check the code reference for wp_enqueue_style and wp_enqueue_script:

    https://developer.wordpress.org/reference/functions/wp_enqueue_style/
    https://developer.wordpress.org/reference/functions/wp_enqueue_script/


  • | 28 points

    add_action('wp_enqueue_scripts', 'load_js');

    Delete the "s" from wp_enqueue_scripts should me wp_enqueue_script


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.