I'm developing a WordPress that utilizes gulp to build the front-end of the application (scss, js) files.
In my functions.php
I use enqueue to load my css and js so that they can be used in the editor.
add_action( 'enqueue_block_editor_assets', function() { wp_enqueue_style( 'editor-styling', get_theme_file_uri( '/dist/styles/main.css', __FILE__) ); wp_enqueue_script( 'editor-scripts', get_theme_file_uri( '/dist/scripts/main.js', __FILE__) ); } );
Running a simple gulp
command I can do the above because the file will be named main.css
. However, I'm facing an issue, when I use gulp --product
, the styles and javascript are suffixed with random values.
For example, my main.scss will (once I run the above command) become main-9acd4829.css
.
My question is, how to get a file from a directory with a file name similar to main<whatever>.css
.
I have tried using something like
get_theme_file_uri(glob('/dist/styles/main*.css'), __FILE__)
But returns null
I think you have to check yourself in a different folder, code inspired by get_theme_file_uri, something like this (note that
glob
returns an array, andget_theme_file_uri
accepts a string):