百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
I

inertia-wordpress

> 编程语言
开源

用于 Inertia.js 的 WordPress 适配器。

182 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

用于 Inertia.js 的 WordPress 适配器。

Inertia.js WordPress Adapter

The unofficial Inertia.js server-side adapter for WordPress.

Installation

Option 1: Install the package via composer. (Recommended)

composer require boxybird/inertia-wordpress

Option 2: Clone or download as a plugin and run composer install before activating in WordPress Admin.

Bare-bones Example Theme

  • https://github.com/boxybird/wordpress-inertia-starter-theme

Example Movie CPT WordPress Project

  • Demo: https://wp-inertia.andrewrhyand.com
  • Theme: https://github.com/boxybird/wordpress-inertia-demo-theme

Inertia Docs

  • Links: https://inertiajs.com/links
  • Pages: https://inertiajs.com/pages
  • Requests: https://inertiajs.com/requests
  • Shared Data: https://inertiajs.com/shared-data
  • Asset Versioning: https://inertiajs.com/asset-versioning
  • Partial Reloads: https://inertiajs.com/partial-reloads

Root Template Example

Location: /wp-content/themes/your-theme/app.php

php

    
        
        
        
    
    

         // Adds Inertia to the page

        
    

Root Template File Override

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.

php

Inertia Response Examples

Basic

Location: /wp-content/themes/your-theme/index.php

php
 $wp_query->posts,
]);

Less Basic

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.

…

Quick Note

You may be wondering what this moster line above does:

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

Shared data

Location: /wp-content/themes/your-theme/functions.php

…

Asset Versioning

Location: /wp-content/themes/your-theme/functions.php

Optional, but helps with cache busting.

php
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);
});

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言