Sage 9 - Plugin scripts not enqueued?


#1

I’m trying to figure out why a plugin’s scripts are not being loaded in footer with the Sage theme.

The plugin in question is https://github.com/Automattic/WP-Job-Manager. It works fine with defaults themes. No additional plugins activated and no js error in browser’s console.

Anyone had a similar issue?


#2

Having the same issue with the scripts of Siteorigin Page Builder.

Script loads in Sage 8.5.0 but in 9.0.0Beta-1 it is not enqueued.


#3

Are you guys sure the page finished loading? If you have an error in your PHP and don’t have errors being displayed, the page may appear to have finished loading but the scripts are not loaded.

Sage does not do anything to dequeue plugin scripts. So I’d check to see if there are any issues. Also, don’t trust chrome inspector for that, as it will add the closing body and html tags. Check the page source and make sure everything looks correct…


#4

Yep, I’m sure. The script is not included in the source, either.

If I switch the theme to Twenty Seventeen the script is loaded, but not in custom theme built with Sage 9.


#5

I’m using this plugin in a Sage 9 site without this problem. This might be a pain but have you tried a fresh copy of Sage without any customizations to rule out a conflict with your code?


#6

This is a fresh installation of trellis, bedrock and Sage 9 beta 1 and installed the Page builder with composer.

But If this works for you, I’ll try again with another new installation.

Thanks so far


#7

Have experienced the same issue with SmartSlider 3 however Page Builder seems to work for me.


#8

I’ve experienced the same with both WooCommerce and Elementor. Disabled all plugins and still the same issue. If I switch theme the scripts is enqueued again.

In this case, the WooCommerce js-file for product variation is not enqueued. I had to enqueue it myself. Also, elementors jquery-numerator.min.js is not enqueued if I use Sage 9.


#9

I just encountered this same problem with WooCommerce Composite Products; the plugin’s styles and scripts were not enqueued. I enqueued them myself but that could become a bear to maintain.

I’ll have to check on the vanilla WooCommerce variations js, too, since you mention it as a problem!

Maybe an action isn’t getting fired or something?


#10

I have the same problem with WordPress Infinite Scroll – Ajax Load More plugin. Works fine in latest Sage 8 but not in a clean WordPress install using Sage 9 beta 3. Any help appreciated…


Sage 9 + woocommerce
#11

I have the same issue with WooCommerce. As far as I can tell the issue is that scripts enqueued in a template (or after the page has started to render) outside of the wp_enqueue_scripts action, will end up enqueuing before the script gets registered, and then fail, because of the way blade renders the page.

This might be a temporary solution (but might introduce new issues?). Only tested with WooCommerce variable products.

In helpers.php change template() to:

/**
 * @param string $file
 * @param array $data
 * @return string
 */
function template($file, $data = [])
{
    if (remove_action('wp_head', 'wp_enqueue_scripts', 1)) {
        wp_enqueue_scripts();
    }

    return sage('blade')->render($file, $data);
}

#12

There’s a GitHub issue for this problem as well.


#13

Although the problem is fixed in sage, this causes another problem for us:

The following two plugins echo out their <style> and <script> tags respectively before the <doctype> declaration:

  • feed-them-social
  • simple-share-buttons-adder

To fix this problem, buffer the output (use ob_start(), etc) of when wp_enqueue_scripts is run, which catches the delinquent printouts of those plugins, so you can print that out properly the first time the wp_head action is run, putting the printouts in the right spot.

# in app/helpers.php
function template($file, $data = [])
{
    global $plugins_printout_head;

    if (remove_action('wp_head', 'wp_enqueue_scripts', 1)) {
        ob_start();
        wp_enqueue_scripts();
        $plugins_printout_head = ob_get_contents();
        ob_end_clean();

        add_action('wp_head', function() {
          global $plugins_printout_head;
          echo $plugins_printout_head;
        }, 1);
    }
    return sage('blade')->render($file, $data);
}

#14

Wow. I would seriously reconsider any plugin coded in that fashion. In the case of Simple Share Buttons Adder, dump it. There are too many negative reviews regarding the amount of redirects it is using.