Community Forums › Forums › Archived Forums › General Discussion › Can't enqueue scripts in child theme functions.php – doesn't output HTML
- This topic has 5 replies, 2 voices, and was last updated 6 years, 1 month ago by Victor Font.
-
AuthorPosts
-
July 30, 2018 at 2:33 pm #222118ColossalYouthMember
Hi there
I'm having a big problem trying to enqueue a script in the Corporate Pro child theme - something I've done with success previously using other child themes.
I've added a line as below to the existing function but nothing is output to the HTML. I can make any number of changes to the existing scripts that are being enqueued alongside it and those changes are reflected in the output, I can also enqueue a style with no problem but I just can't add this jQuery file.
Any idea what might be causing this?
add_action( 'wp_enqueue_scripts', 'corporate_scripts_styles', 90 ); function corporate_scripts_styles() { // Enqueue Retina image swap. wp_enqueue_script( CHILD_TEXT_DOMAIN . '-imgx', CHILD_THEME_URI . '/assets/scripts/min/imgx.min.js', array( 'jquery' ), CHILD_THEME_VERSION, true ); // Enqueue custom theme scripts. wp_enqueue_script( CHILD_TEXT_DOMAIN . '-pro', CHILD_THEME_URI . '/assets/scripts/theme.js', array( 'jquery' ), CHILD_THEME_VERSION, true ); // Disable superfish args. wp_deregister_script( 'superfish-args' ); }
I've also tried this to keep things simple, but nothing:
wp_enqueue_script( 'imgx-image-swap', get_stylesheet_directory_uri() . '/assets/scripts/min/imgx.min.js', false, null );
Many thanks for helping.
July 30, 2018 at 3:51 pm #222120Victor FontModeratorIn the first example, assuming the constant values are correct, you syntax appears to be correct also. The olny thing I see that's odd is the ad_action has a priority of 90. That's a little high, so your scripts are loading very late in the stack. Since they're not loading at all, your scripts may be victims of a timing issue because of that high priority.
Your syntax of off in the second example. You are missing the dependencies and the last value should be true or false to indicate loading in the footer or header.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?July 30, 2018 at 5:01 pm #222121ColossalYouthMemberThanks Victor
My bad, I typed that last bit of code directly in the input box here and mixed up 'ver' and 'in_footer'.
Yeah I just can't see what could be wrong in the first example, I'm pretty confident it's not the priority at fault because the other existing scripts without that function load fine, it's just any script that I subsequently add myself won't output in the necessary HTML at all. I'm wondering whether I need to register the script elsewhere or there's some other reference I'm missing? I dug around in the various includes but found nothing relevant.
I did play around with the priority to see if that helped but there was no change.
July 30, 2018 at 5:39 pm #222122ColossalYouthMember*within that function, of course
July 30, 2018 at 6:03 pm #222123ColossalYouthMemberGood grief, I've spent hours on this and just discovered it was an EOL conversation issue as outlined here:
https://stackoverflow.com/questions/16239551/eol-conversion-in-notepadCommenting in the PHP was breaking the file because Notepad++ had reverted to 'Old Mac Format' for no apparent reason.
Sorry for the hassle Victor.
July 31, 2018 at 5:37 am #222131Victor FontModeratorNo hassle! Glad you figured it out.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet? -
AuthorPosts
- The topic ‘Can't enqueue scripts in child theme functions.php – doesn't output HTML’ is closed to new replies.