Skip to content
Acorn
v4.3.1

Acorn is a framework for integrating Laravel within WordPress

Write modern PHP in WordPress — Acorn brings Laravel’s developer experience where you need it

Integrate Laravel’s features into your WordPress projects for cleaner, more maintainable code with familiar patterns and tools.

$ composer require roots/acorn
$ wp acorn

USAGE: wp acorn [command] [options] [arguments]

make:command          Create a new Artisan command
make:component        Create a new view component class
make:composer         Create a new view composer class
make:controller       Create a new controller class
make:job              Create a new job class
make:middleware       Create a new HTTP middleware class
make:migration        Create a new migration file
make:provider         Create a new service provider class
make:queue-table      Create a migration for the queue jobs database table
make:queue-table      Create a migration for the queue jobs database table
make:seeder           Create a new seeder class

migrate:fresh         Drop all tables and re-run all migrations
migrate:install       Create the migration repository
migrate:refresh       Reset and re-run all migrations
migrate:reset         Rollback all database migrations
migrate:rollback      Rollback the last database migration
migrate:status        Show the status of each migration

optimize:clear        Remove the cached bootstrap files

package:discover      Rebuild the cached package manifest

queue:work            Start processing jobs on the queue as a daemon

route:cache           Create a route cache file for faster route registration
route:clear           Remove the route cache file
route:list            List all registered routes

vendor:publish        Publish any publishable assets from vendor packages

view:cache            Compile all of the application's Blade templates
view:clear            Clear all compiled view files
  

$ wp acorn optimize

INFO Caching framework bootstrap, configuration, and metadata.

config .............................................................. 9.30ms DONE
events ............................................................. 29.91ms DONE
routes .............................................................. 4.99ms DONE
views .............................................................. 50.15ms DONE

Blade templates in WordPress

Use Laravel’s powerful Blade templating engine throughout WordPress. Create cleaner, more maintainable templates with layouts, components, and directives. Render WordPress blocks, emails, and more with the template engine loved by PHP developers worldwide.

Rendering WordPress blocks with Blade

views/blocks/button.blade.php

<x-button
    variant="{{ $variant }}"
    class="{{ $classes }}"
    href="{{ $href }}"
>
    {{ $text }}
</x-button>

Example Blade template

views/layouts/app.blade.php

<div class="flex flex-col h-screen">
    <div>
        @include('sections.header')
    </div>

    <main>
        @yield('content')
    </main>

    @include('sections.footer')
</div>

Laravel migrations for your WordPress projects

Use Laravel’s migration system to manage your WordPress database schema. Create, modify, and version your database structure with elegant PHP syntax.

Create & run migrations via WP-CLI

$ wp acorn make:migration

┌ What should the migration be named? ─────┐
 create_example_table                     
└──────────────────────────────────────────┘

INFO Migration [create_example_table.php] created successfully.

$ wp acorn migrate

INFO Running migrations.

create_example_table ...................... DONE

database/migrations/create_example_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
    public function up()
    {
        Schema::create('example', function (Blueprint $table) {
            $table->id();
            $table->string('example');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('example');
    }
};

Laravel routing in WordPress

Create virtual pages and custom endpoints without wrestling with WordPress rewrite rules. Define routes with clean syntax, middleware support, and named routes.

Registering routes

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

Route::get('/welcome/', function () {
    return view('welcome');
});

Error handling & logging

Capture and diagnose errors more effectively with Laravel’s exception handling and logging. Track issues in development and production with structured logs.

Advanced logging

example.php

<?php

use Illuminate\Support\Facades\Log;

Log::debug('👋 Howdy');

Supported Laravel components

  • illuminate/bus
  • illuminate/cache
  • illuminate/collections
  • illuminate/conditionable
  • illuminate/config
  • illuminate/console
  • illuminate/container
  • illuminate/contracts
  • illuminate/database
  • illuminate/encryption
  • illuminate/events
  • illuminate/filesystem
  • illuminate/hashing
  • illuminate/http
  • illuminate/log
  • illuminate/macroable
  • illuminate/pipeline
  • illuminate/queue
  • illuminate/routing
  • illuminate/session
  • illuminate/support
  • illuminate/validation
  • illuminate/view
  • Sponsors

    Help support our open-source development efforts

    Subscribe for updates

    Join over 8,000 subscribers on our newsletter to get the latest Roots updates and tips on building better WordPress sites

    Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?