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

Fix script and style enqueuing #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mAAdhaTTah
Copy link

Currently, the load_resources function in the front.php file is loading the scripts and styles in the footer. On our install, we're not seeing the CSS files enqueued at all.

This should be hooked into the wp_enqueue_scripts action. This PR fixes that.

@jewlofthelotus
Copy link
Owner

@mAAdhaTTah The CSS files are enqueued using wp_enqueue_style in the load_resources method - on line 48

What exactly did the change you made do? The CSS files were not loading at all and then this made them load? Or in a particular spot?

@mAAdhaTTah
Copy link
Author

Yeah, the load_resources function is being called in the wp_footer hook. wp_enqueue_styles wants to put the styles in the header in the <head>, but it can't because when wp_footer is called, the <head> has already been output.

Generally speaking, scripts and styles should be called in the wp_enqueue_scripts hook (or admin_enqueue_scripts on the admin side), which is when WordPress is dealing with all its internal scripts/styles. You can also fix the way the slickQuiz.js file is enqueued, by requiring the dependency on jquery in that function call rather than asking WordPress to enqueue it again (which it doesn't do twice anyway), which will make sure everything is enqueued in the right order.

I know this may be a little unclear, so I can update this PR to show what I mean. The short version is the plugin enqueues its scripts/styles on the wrong hook. This fixes that.

@mAAdhaTTah
Copy link
Author

(Also, wp_footer is an action, not a filter, tho it seems to work anyway. That's why I changed that second line.)

@joshuadavidnelson
Copy link

I'm looking to filter off the scripts and styles on everything but single post templates, which will be easy with enqueuing of the assets. Any reason why this hasn't been merged or anything I can do to help move it along?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants