• Resolved stevemullen

    (@stevemullen)


    I am investigating plugins on my site that are not loading scripts and styles correctly. multisite-enhancements is active on this site, and while reading that plugin code, I cam across this:

    inc/autoload/class-add-css.php:
    add_action( 'admin_head-themes.php', array( $this, 'enqueue_style' ) );

    I know that the correct way to enqueue scripts and styles is to use one of the action hooks ‘wp_enqueue_scripts’, ‘admin_enqueue_scripts’, or ‘login_enqueue_scripts’. What I’m not clear on, is if you’ve created an action called ‘admin_head-themes.php’ that is allowing you to do this the proper way. Or maybe this is just old code that needs to be updated to the newer way of loading.

    My problem is that WP is generating a warning because code (plugins, themes…) are not loading scripts and styles correctly, but the warning is not indicating the offending code:

    [12-Apr-2019 12:57:45 UTC] PHP Notice: wp_register_script was called <strong>incorrectly</strong>. Scripts and styles should not be registered or enqueued until the <code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or <code>login_enqueue_scripts</code> hooks. Please see <a href="https://codex.www.ads-software.com/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.3.0.) in /home/redacted/public_html/wp-includes/functions.php on line 4667

    Your thoughts on this would be appreciated.

    Thank you

    The page I need help with: [log in to see the link]

  • The topic ‘PHP Notice: wp_enqueue_script called correctly?’ is closed to new replies.