Skip to main content

Support for EtchWP

When using SCSS and loading “Everywhere”, the stylesheet doesn’t load with the Etch builder.

1 comment

Log in to comment and vote

Comments1

  • manuel-will

    •

    May 20

    Etch runs isolated therefore it won’t accept external sheets. But here is a snippet to make it work - just use it inside SnipVault:

    <?php
    // Prevent direct access to this file
    defined("ABSPATH") || exit();
    
    add_action("etch/canvas/enqueue_assets", function () {
      $upload = wp_upload_dir();
      $dir = trailingslashit($upload["basedir"]) . "snipvault";
      $url = trailingslashit($upload["baseurl"]) . "snipvault";
    
      if (!is_dir($dir)) {
        return;
      }
    
      foreach (glob($dir . "/*.css") ?: [] as $file) {
        $basename = basename($file);
        wp_enqueue_style(
          "snipvault-" . sanitize_key(basename($file, ".css")),
          $url . "/" . $basename,
          [],
          (string) filemtime($file)
        );
      }
    
      foreach (glob($dir . "/*.js") ?: [] as $file) {
        $basename = basename($file);
        wp_enqueue_script(
          "snipvault-" . sanitize_key(basename($file, ".js")),
          $url . "/" . $basename,
          [],
          (string) filemtime($file),
          true
        );
      }
    });