PHPackages                             morningtrain/wp-enqueue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. morningtrain/wp-enqueue

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

morningtrain/wp-enqueue
=======================

A tool for enqueueing assets in WordPress with support for Laravel Mix manifest

v1.3.2(2y ago)52.2kMITPHPPHP ^8.0

Since Jun 16Pushed 2y ago4 watchersCompare

[ Source](https://github.com/Morning-Train/wp-enqueue)[ Packagist](https://packagist.org/packages/morningtrain/wp-enqueue)[ RSS](/packages/morningtrain-wp-enqueue/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (13)Used By (0)

WP Enqueue
==========

[](#wp-enqueue)

For easy script and style enqueueing in WordPress. With Laravel Mix Manifest and WP-Scripts asset file support!

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Getting Started](#getting-started)
    - [Installation](#installation)
- [Usage](#usage)
    - [Before you start](#before-you-start)
    - [Defining the root Url](#defining-the-root-url)
    - [Adding a MixManifest file](#adding-a-mixmanifest-file)
    - [Loading scripts and styles](#loading-scripts-and-styles)
        - [Enqueueing](#enqueueing)
            - [Registering](#registering)
    - [Options](#options)
        - [Script](#script)
        - [Style](#style)
    - [Namespacing](#namespacing)
- [Credits](#credits)
- [Testing](#testing)
- [License](#license)

Introduction
------------

[](#introduction)

This tool is made for making the enqueueing and registering of WordPress scripts a bit more expressive and to make using laravel Mix Manifest much easier to manage.

This tool lets you:

- Define a root URL for your scripts and stylesheets so that you only have to use `get_stylesheet_directory_uri` once and instead use relative paths when enqueueing
- Add your `mix-manifest.json` file so that all mix compiled assets gets hashed automatically
- Use a fluid interface for enqueueing assets

Getting Started
---------------

[](#getting-started)

Fist [install](#installation) the package!

Then from here on your entry point will be `\Morningtrain\WP\Enqueue\Enqueue`.

### Installation

[](#installation)

This tool is available as a package and can be installed through composer:

```
composer require morningtrain/wp-enqueue

```

Usage
-----

[](#usage)

Here is a quick example of how this package works!

```
use Morningtrain\WP\Enqueue\Enqueue;

// functions.php (or plugin.php)
Enqueue::setup(get_stylesheet_directory_uri() . "/public/build", get_stylesheet_directory() . "/public/build");

// Then wherever you wish to enqueue - preferably in the wp_enqueue_scripts action
Enqueue::script('main')
    ->src('js/main.js')
    ->deps('jquery')
    ->applyAssetFile() // This applies the main.asset.php file containing dependencies and version. Dependencies are pushed to existing dependencies
    ->enqueue();

// Or to simply register a stylesheet
Enqueue::style('main')
    ->src('css/main.css')
    ->register();

// 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

[](#before-you-start)

All relative paths should match paths in `webpack.mix.js`.

So if you have the following in your mix:

```
// webpack.mix.js

let mix = require('laravel-mix');

mix.js('resources/js/app.js', 'js').setPublicPath('public/build');
```

Then your public directory would be `public/build` and all assets would use a source relative to this path. So in the above example, you would enqueue `app.js` like this:

```
Enqueue::script('app', 'js/app.js')->enqueue();
```

Note: Enqueueing assets before the `wp_enqueue_scripts` hook will automatically delay the enqueueing until WordPress is ready. You should, of course, still enqueue properly in the right hook.

### Defining the root Url

[](#defining-the-root-url)

You may define the root URL of your build directory.

By doing this you can now enqueue assets using a relative path. This should match the one defined in `webpack.mix.js` if you are using [Laravel Mix](https://laravel-mix.com/)

```
// Setting the root URL
\Morningtrain\WP\Enqueue\Enqueue::setRootUrl(get_stylesheet_directory_uri() . '/public/build');
```

You may also get the url by calling `Enqueue::getRootUrl()`

```
// Getting the root URL
$rootUrl = \Morningtrain\WP\Enqueue\Enqueue::getRootUrl();
```

### Adding a MixManifest file

[](#adding-a-mixmanifest-file)

If you are using [Laravel Mix](https://laravel-mix.com/) then you can add the generated `mix-manifest.json` file. By doing this all enqueued assets will automatically use the hashed sources.

This is an easy and convenient way to clear client cached assets without worry.

```
// Adding the manifest file
\Morningtrain\WP\Enqueue\Enqueue::addManifest(get_stylesheet_directory() . '/public/build/mix-manifest.json');
```

You may also retrieve the manifest content

```
// Adding the manifest content
\Morningtrain\WP\Enqueue\Enqueue::getManifest();
```

### Loading scripts and styles

[](#loading-scripts-and-styles)

Loading a script or a style is almost the same! Construct either a `Script` or a `Style` from `Enqueue`

Then, using a fluid api, you can configure your asset and then either enqueue or register at the end.

Note: These methods act the same as, and wraps, WordPress methods [wp\_enqueue\_script()](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)and [wp\_enqueue\_style()](https://developer.wordpress.org/reference/functions/wp_enqueue_style/) and their register equivalents.

```
// Beginning an Enqueue chain
// This is how you start enqueueing or registering a script
\Morningtrain\WP\Enqueue\Enqueue::script('my-script');
// ... and for a stylesheet
\Morningtrain\WP\Enqueue\Enqueue::style('my-style');
```

After this inspect the instance returned. All options are available as chainable methods!

#### Enqueueing

[](#enqueueing)

To enqueue simply end your chain by calling `enqueue()`

```
// Enqueue a script called 'my-script' which is located in the /js directory
\Morningtrain\WP\Enqueue\Enqueue::script('my-script')
    ->src('js/my-script.js')
    ->enqueue();

// Or you may supply the source as the second param as so
\Morningtrain\WP\Enqueue\Enqueue::script('my-script', 'js/my-script.js')
    ->enqueue();
```

##### Registering

[](#registering)

To register instead of enqueueing use `register()`

```
// Register a script called 'my-script' which is located in the /js directory
\Morningtrain\WP\Enqueue\Enqueue::script('my-script')
    ->src('js/my-script.js')
    ->register();
```

Then later you can enqueue your asset this way:

```
// Enqueue a script called 'my-script' which has already been registered
\Morningtrain\WP\Enqueue\Enqueue::script('my-script')
    ->enqueue();
```

### Options

[](#options)

There are the same options as the methods these classes wrap.

**Note:** `deps()` also accepts a string and if you call it multiple times in the same chain then every call pushes its value to the list.

#### Script

[](#script)

Here is an example using all available options:

See [wp\_enqueue\_script](https://developer.wordpress.org/reference/functions/wp_enqueue_script/) on developer.wordpress.org

```
\Morningtrain\WP\Enqueue\Enqueue::script('my-script')
    ->src('js/my-script.js')
    ->deps('jquery')
    ->ver('1.0')
    ->inFooter(true)
    ->enqueue();
```

#### Style

[](#style)

Here is an example using all available options:

See [wp\_enqueue\_style](https://developer.wordpress.org/reference/functions/wp_enqueue_style/) on developer.wordpress.org

```
\Morningtrain\WP\Enqueue\Enqueue::style('my-style')
    ->src('css/my-style.css')
    ->deps('print-styles')
    ->ver('1.0')
    ->media('print')
    ->enqueue();
```

### Namespacing

[](#namespacing)

You may register a namespace for a set of scripts or styles that live somewhere else in your codebase.

To do this simple add the namespace and then use this namespace in your handles. Namespacing is especially useful when writing a plugin.

#### Adding a namespace

[](#adding-a-namespace)

```
\Morningtrain\WP\Enqueue\Enqueue::addNamespace('myPlugin',\plugin_dir_url(__FILE__). "public/build", __DIR__ . "/public/build/mix-manifest.json");
```

#### Using a namespace

[](#using-a-namespace)

```
\Morningtrain\WP\Enqueue\Enqueue::style('myPlugin::main')
    ->src('css/main.css')
    ->enqueue();
```

Credits
-------

[](#credits)

- [Mathias Munk](https://github.com/mrmoeg)
- [All Contributors](../../contributors)

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 90.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~37 days

Recently: every ~92 days

Total

12

Last Release

1055d ago

Major Versions

v0.2.1 → v1.0.02022-06-29

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/278725?v=4)[morningtrain](/maintainers/morningtrain)[@morningtrain](https://github.com/morningtrain)

![](https://avatars.githubusercontent.com/u/5990117?v=4)[Mathias Munk](/maintainers/mrmoeg)[@mrmoeg](https://github.com/mrmoeg)

---

Top Contributors

[![mrmoeg](https://avatars.githubusercontent.com/u/5990117?v=4)](https://github.com/mrmoeg "mrmoeg (48 commits)")[![mschadegg](https://avatars.githubusercontent.com/u/11231039?v=4)](https://github.com/mschadegg "mschadegg (4 commits)")[![matbaek](https://avatars.githubusercontent.com/u/2310644?v=4)](https://github.com/matbaek "matbaek (1 commits)")

---

Tags

wordpressenqueuemorningtrain

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/morningtrain-wp-enqueue/health.svg)

```
[![Health](https://phpackages.com/badges/morningtrain-wp-enqueue/health.svg)](https://phpackages.com/packages/morningtrain-wp-enqueue)
```

###  Alternatives

[aristath/kirki

Extending the WordPress customizer

1.3k73.1k4](/packages/aristath-kirki)[afragen/git-updater

A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs.

3.3k1.7k](/packages/afragen-git-updater)[tacowordpress/tacowordpress

WordPress custom post types that feel like CRUD models

232.2k](/packages/tacowordpress-tacowordpress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
