Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp_enqueue_style example brings E_NOTICE #1575

Closed
cweiske opened this issue Jun 2, 2024 · 8 comments
Closed

wp_enqueue_style example brings E_NOTICE #1575

cweiske opened this issue Jun 2, 2024 · 8 comments
Assignees
Labels
developer documentation (DevHub) Improvements or additions to developer documentation [Status] Done Issue is completed themes Issues for Theme Developer Handbook

Comments

@cweiske
Copy link

cweiske commented Jun 2, 2024

Issue Description

I followed the "adding your stylesheet" instructions at https://developer.wordpress.org/themes/basics/including-css-javascript/#stylesheets and got an E_NOTICE from my wordpress 6.5 instance:

To enqueue style.css:
wp_enqueue_style( 'style', get_stylesheet_uri() );
This will look for a stylesheet named “style” and load it.

Message I got from wordpress:

Notice: Function wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. This notice was triggered by the style handle. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in wordpress/wp-includes/functions.php on line 6078

URL of the Page with the Issue

https://developer.wordpress.org/themes/basics/including-css-javascript/#stylesheets

Section of Page with the issue

Enqueuing Scripts and Styles > Stylesheets

Why is this a problem?

The documentation should tell me what I have to do to make it right, not provide code that gives errors.

Suggested Fix

Already tell about the wp_enqueue_scripts function.

@cweiske cweiske added the [Status] To do Issue marked as Todo label Jun 2, 2024
Copy link

github-actions bot commented Jun 2, 2024

Heads up @WordPress/docs-issues-coordinators, we have a new issue open. Time to use 'em labels.

@estelaris estelaris added developer documentation (DevHub) Improvements or additions to developer documentation themes Issues for Theme Developer Handbook labels Jun 3, 2024
Copy link

github-actions bot commented Jun 3, 2024

Heads up @kafleg @carolinan @TeBenachi - the "themes" label was applied to this issue.

@carolinan
Copy link
Collaborator

So how can readers be encouraged to continue reading and not only copy part of the code example?

@cweiske
Copy link
Author

cweiske commented Jun 4, 2024

I copied the whole example.
The section at the end of the page tells you that

It is best to combine all enqueued scripts and styles into a single function

- but even it does not tell you that all the previous examples were incomplete.

@justintadlock
Copy link

justintadlock commented Jun 5, 2024

The relevant documentation for including assets is here and includes more in-depth examples: https://developer.wordpress.org/themes/core-concepts/including-assets/

I'm not sure how we might want to address the current page since it will be deprecated/removed or integrated into the Classic Themes chapter as part of #816. The information isn't wrong. It just assume some preexisting knowledge about the correct hooks to use (this isn't the case with the newer doc).

Maybe, for now (at least until the Classic Themes chapter is overhauled), we should put an alert banner at the top of the page to redirect readers to the new doc??

@estelaris
Copy link
Member

@justintadlock that is a good solution. Are you able to update the article?

@justintadlock justintadlock self-assigned this Jun 6, 2024
@github-actions github-actions bot added [Status] In progress Issue is in progress and removed [Status] To do Issue marked as Todo labels Jun 6, 2024
@justintadlock
Copy link

Updated and added an alert box to go to the newer doc: https://developer.wordpress.org/themes/basics/including-css-javascript/

@github-actions github-actions bot added [Status] Done Issue is completed and removed [Status] In progress Issue is in progress labels Jun 6, 2024
@cweiske
Copy link
Author

cweiske commented Jun 7, 2024

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer documentation (DevHub) Improvements or additions to developer documentation [Status] Done Issue is completed themes Issues for Theme Developer Handbook
4 participants