![]() \ Morningtrain\ WP\ Enqueue\ Enqueue:: script( 'my-script', 'js/my-script.js') Or you may supply the source as the second param as so \ Morningtrain\ WP\ Enqueue\ Enqueue:: script( 'my-script') To enqueue simply end your chain by calling enqueue() // Enqueue a script called 'my-script' which is located in the /js directory All options are available as chainable methods! Enqueueing \ Morningtrain\ WP\ Enqueue\ Enqueue:: style( 'my-style') Īfter this inspect the instance returned. Beginning an Enqueue chain // This is how you start enqueueing or registering a script Note: These methods act the same as, and wraps, WordPressĪnd wp_enqueue_style() and their registerĮquivalents. Then, using a fluid api, you can configure your asset and then either enqueue or register at the end. Loading a script or a style is almost the same!Ĭonstruct either a Script or a Style from Enqueue \ Morningtrain\ WP\ Enqueue\ Enqueue:: getManifest() Loading scripts and styles ![]() You may also retrieve the manifest content // Adding the manifest content \ Morningtrain\ WP\ Enqueue\ Enqueue:: addManifest(get_stylesheet_directory(). This is an easy and convenient way to clear client cached assets without worry. Byĭoing this all enqueued assets will automatically use the hashed sources. If you are using Laravel Mix then you can add the generated mix-manifest.json file. You may also get the url by calling Enqueue::getRootUrl() // Getting the root URL $rootUrl = \ Morningtrain\ WP\ Enqueue\ Enqueue:: getRootUrl() Adding a MixManifest file \ Morningtrain\ WP\ Enqueue\ Enqueue:: setRootUrl(get_stylesheet_directory_uri(). You are using Laravel Mix // Setting the root URL You may define the root URL of your build directory.īy doing this you can now enqueue assets using a relative path. You should, of course, still enqueue properly in the right hook. Note: Enqueueing assets before the wp_enqueue_scripts hook will automatically delay the enqueueing until WordPress is So in theĪbove example, you would enqueue app.js like this: Enqueue:: script( 'app', 'js/app.js')-> enqueue() Then your public directory would be public/build and all assets would use a source relative to this path. So if you have the following in your mix: // let mix = require ( 'laravel-mix' ) mix. In a block, on a route or in a condition somewhere you can now enqueue the already registered stylesheet Enqueue:: style( 'main')-> enqueue() Before you startĪll relative paths should match paths in. Or to simply register a stylesheet Enqueue:: style( 'main') Dependencies are pushed to existing dependencies > applyAssetFile() // This applies the file containing dependencies and version. Then wherever you wish to enqueue - preferably in the wp_enqueue_scripts action Enqueue:: script( 'main') " /public/build", get_stylesheet_directory(). functions.php (or plugin.php) Enqueue:: setup(get_stylesheet_directory_uri(). Here is a quick example of how this package works! use Morningtrain\ WP\ Enqueue\ Enqueue This tool is available as a package and can be installed through composer: composer require morningtrain/wp-enqueue Then from here on your entry point will be \Morningtrain\WP\Enqueue\Enqueue. Use a fluid interface for enqueueing assets.Add your mix-manifest.json file so that all mix compiled assets gets hashed automatically.Define a root URL for your scripts and stylesheets so that you only have to use get_stylesheet_directory_uri onceĪnd instead use relative paths when enqueueing. ![]() ![]() Laravel Mix Manifest much easier to manage. This tool is made for making the enqueueing and registering of WordPress scripts a bit more expressive and to make using With Laravel Mix Manifest and WP-Scripts asset file support! Table of Contents For easy script and style enqueueing in WordPress.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |