• WP v 5.8
    PHP 7.4 (also tried 8.0, no diff)
    Host 1&1
    2 sites running WP since 2007, so experienced user here.

    Since 5.8 update, using a custom theme since 2007, I am seeing printed out on every page the following error message at the end of the page:

    Warning: Invalid argument supplied for foreach() in xxxxxxxx/wp-includes/script-loader.php on line 2652

    A google search shows MANY other users websites are showing same message relating to line 2652. And I have 2 sites, and both are affected.

    Message is not present if I use a modern 2021 theme, so it is related to my custom theme somehow. That said, the theme is worked perfectly since 2007 and is very basic, so a WP change caused this problem.

    Also, I notice that if I remove:
    <?php wp_footer(); ?>

    from footer.php, the message goes away, but it seems as though that code SHOULD be present in all themes, so that is not a solution.

    I have also experimented with tweaking the themes functions.php file, but even making that file empty does not solve the problem.

    Help will be appreciated, thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter festusdog

    (@festusdog)

    Also, further information… the error message does not display if I am logged into the site and viewing the site. But logged out — the way any visitor would view the site — the error message is printed.

    I want to solve the problem, not just hide the error message.

    Thread Starter festusdog

    (@festusdog)

    OK, I will answer the question myself, and share with anyone else who may be having same problem.

    In your HEAD section, you are missing a PHP statement.

    Example of what it should have:

    <head>
    <!– First add the elements you need in <head>; then last, add: –>
    <?php wp_head(); ?>
    </head>

    So, the problem is that I was missing the line:
    <?php wp_head(); ?>

    Putting that directly before the </head> tage fixes the problem.

    Thread Starter festusdog

    (@festusdog)

    And FYI, that is found in your header.php file

    You can easily fix this without using the wp_head() by adding $wp_styles = wp_styles() in your own custom header code.
    wp_head() adds a lot of data that you might not always want to use.

    <?php $wp_styles = wp_styles(); ?>

    @segevmoran – Thank you for your solution. It worked on all my custom theme pages where I had decided to not use wp_head(). Regards.

    @festusdog : Thank you very much for posting the solution! ??
    @segevmoran : Thank you for your special solution ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Since 5.8, theme error foreach script-loader.php line 2652’ is closed to new replies.