• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Can't enqueue scripts in child theme functions.php – doesn't output HTML

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Can't enqueue scripts in child theme functions.php – doesn't output HTML

This topic is: resolved

Tagged: enqueue, jquery, script

  • This topic has 5 replies, 2 voices, and was last updated 4 years, 6 months ago by Victor Font.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • July 30, 2018 at 2:33 pm #222118
    ColossalYouth
    Member

    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 #222120
    Victor Font
    Moderator

    In 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 #222121
    ColossalYouth
    Member

    Thanks 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 #222122
    ColossalYouth
    Member

    *within that function, of course

    July 30, 2018 at 6:03 pm #222123
    ColossalYouth
    Member

    Good 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-notepad

    Commenting 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 #222131
    Victor Font
    Moderator

    No 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?

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Can't enqueue scripts in child theme functions.php – doesn't output HTML’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble