0

I have searched your site but cannot find and fix this error I get:

Notice: Function wp_enqueue_style 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. This notice was triggered by the <code>editor-buttons</code> handle. Please see <a href="https://wordpress.org/support/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 3.3.0.) in /wp-includes/functions.php on line 5835

In my functions.php I have:

//from: https://kinsta.com/blog/twenty-seventeen-theme/
// Also found: https://make.wordpress.org/training/handbook/lesson-plans/theme-school/child-themes/child-themes-twentyseventeen/
function childtheme_enqueue_styles() {
  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

  wp_enqueue_style( 'child-style',
    get_stylesheet_directory_uri() . '/style.css',
    array( 'parent-style' ),
    wp_get_theme()->get('Version')
  );
}
add_action( 'wp_enqueue_scripts', 'childtheme_enqueue_styles' );
 
 
 // Method 2: Exclude a Category from WordPress Homepage Using Code
 // As at: https://www.wpbeginner.com/wp-tutorials/how-to-exclude-a-category-from-your-wordpress-homepage/
 function exclude_webapps_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-49' ); // MUST use 'cat' for category and '-ID' for category ID
}
return $query;
}

add_filter( 'pre_get_posts', 'exclude_webapps_home' );

?>

What must I change? Can you help? I have no plugins or messed otherwise with the editor-buttons. I am on WordPress 6.1

6
  • Like the error message says, you need to call wp_enqueue_style only from within certain hooks. Whatever is calling childtheme_enqueue_styles is doing it wrong (though the caller and this function are probably both from the same provider).
    – tripleee
    Commented Nov 9, 2022 at 11:46
  • @tripleee I have nowhere else childtheme_enqueue_styles called. This is the only place.
    – Prink1978
    Commented Nov 9, 2022 at 11:50
  • This is the definition of the function, something is calling the function in order for the error message to trigger. Search for childtheme_enqueue_styles() without function in front of it.
    – tripleee
    Commented Nov 9, 2022 at 11:54
  • @tripleee Where should I look? The code I provided is the whole of my functions.php What must I correct in my functions.php?
    – Prink1978
    Commented Nov 9, 2022 at 11:58
  • Something is calling it; the fact that it's in includes probably means something else will include it when it runs.
    – tripleee
    Commented Nov 9, 2022 at 12:00

1 Answer 1

0

I think you can try with this code below.

function childtheme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->parent()->get('Version') );

    wp_enqueue_style( 'child-style',
        get_stylesheet_uri(),
        array( 'parent-style' ),
        wp_get_theme()->get('Version') // Note you must provide a version into the child theme
    );
}
add_action( 'wp_enqueue_scripts', 'childtheme_enqueue_styles' );
1
  • Thank you for your answer. Just tried it. Unfortunately there is no difference.
    – Prink1978
    Commented Nov 9, 2022 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.