The WordPress adapter for Inertia.js.
The unofficial Inertia.js server-side adapter for WordPress.
Option 1: Install the package via composer. (Recommended)
composer require boxybird/inertia-wordpressOption 2: Clone or download as a plugin and run composer install before activating in WordPress Admin.
Location: /wp-content/themes/your-theme/app.php
// Adds Inertia to the page
Location: /wp-content/themes/your-theme/functions.php
By default the WordPress adapter will use the app.php from .../your-theme/app.php. If you would like to use a different file name, you can change it. E.g. .../your-theme/layout.php.
Location: /wp-content/themes/your-theme/index.php
$wp_query->posts,
]);Location: /wp-content/themes/your-theme/index.php
This may look busy, however it can be thought of as a "Controller". It gives you a place to handle all your business logic. Leaving your Javacript files easier to reason about.
…You may be wondering what this moster line above does:
'content' => apply_filters('the_content', get_the_content(null, false, $post->ID));Because we can't use the WordPress function the_content() outside of a traditional theme template setup, we need to use get_the_content() instead. However, we first need to apply the filters other plugins and WordPress have registered.
Matter of fact, we can't use any WordPress function that uses echo, and not return.
But don't fret. WordPress typically offers a solution to this caveat: get_the_title() vs the_title(), get_the_ID() vs the_ID(), and so on...
Reference: https://developer.wordpress.org/reference/functions/
Location: /wp-content/themes/your-theme/functions.php
…Location: /wp-content/themes/your-theme/functions.php
Optional, but helps with cache busting.
add_action('init', function () {
// If you're using Laravel Mix, you can
// use the mix-manifest.json for this.
$version = md5_file(get_stylesheet_directory() . '/mix-manifest.json');
Inertia::version($version);
});No open issues yet, or sync has not completed.