PHPackages                             oberonlai/wp-template - 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. [Templating &amp; Views](/categories/templating)
4. /
5. oberonlai/wp-template

ActiveLibrary[Templating &amp; Views](/categories/templating)

oberonlai/wp-template
=====================

Register and render templates from your plugin.

v1.0.7(4y ago)07MITPHPPHP &gt;=7.2

Since Nov 19Pushed 4y ago1 watchersCompare

[ Source](https://github.com/oberonlai/wp-template)[ Packagist](https://packagist.org/packages/oberonlai/wp-template)[ Docs](https://github.com/oberonlai/wp-template)[ RSS](/packages/oberonlai-wp-template/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (8)Used By (0)

PageTemplates
=============

[](#pagetemplates)

A simple class that allows registering WordPress any templates from plugins. Including page templates, custom post type templates and WooCommerce templates

Installation
------------

[](#installation)

```
$ composer require oberonlai/wp-template

```

Usage
-----

[](#usage)

First, initialize the class with the plugin's directory path and template folder. For example, if you place the template files in a folder which name is 'templates', you can assing the path.

```
use ODS\Template;
$template = new Template( plugin_dir_path( __FILE__ ) . 'templates/' );
```

Don't forget the last slash in folder path.

### Add page template

[](#add-page-template)

Page template is the template can be used repeatedly in page editor. You can use `add_page()` to assign the page template. There are two arguments in `add_page()`:

- $file - The page template file name
- $name - Human-readable template name

```
use ODS\Template;
$template = new Template( plugin_dir_path( __FILE__ ) . 'templates/' );
$template->add_page( 'template-demo.php', 'my-template' );
```

### Add page slug template.

[](#add-page-slug-template)

Page slug template is the template for same slug name. You can use the `page-demo.php` template if your page slug's name is 'demo'. There are two arguments:

- $file The page template file name
- $slug For matched page slug

```
use ODS\Template;
$template = new Template( plugin_dir_path( __FILE__ ) . 'templates/' );
$template->add_page_slug( 'page-test.php', 'test' );
```

### Add custom post type template

[](#add-custom-post-type-template)

Custom post type template includes single and archive page. You can use the method `add_post()` to assign template file. There are three arguments :

- $file The page template file name
- $type Custom post type name
- $position Template position optional single, archive

```
use ODS\Template;
$template = new Template( plugin_dir_path( __FILE__ ) . 'templates/' );
$template->add_post( 'single-book.php', 'book', 'single' );
$template->add_post( 'archive-book.php', 'book', 'archive' );
```

### Override WordPress template

[](#override-wordpress-template)

WordPress template includes serveral filters to override.

[https://developer.wordpress.org/reference/hooks/type\_template/](https://developer.wordpress.org/reference/hooks/type_template/)

You can use the method `add_wp()` to assign template file. There are three arguments:

- $file The page template file name
- $position Template position

```
use ODS\Template;
$template = new Template( plugin_dir_path( __FILE__ ) . 'templates/' );
$template->add_wp( 'author.php', 'author' );
$template->add_wp( '404.php', '404' );
```

### Override WooCommerce template

[](#override-woocommerce-template)

WooCommerce template has its own hierarchy. All you need to do is copy the WooCommerce template file you need to the template folder in your plugin.

You can use the method `add_woocommerce()` to change the default template path of WooCommerce. It will get the original template file if your plugin doesn't have the same name with WooCommerce template in templates/woocommerce path.

For example, if you have `form-checkout.php` file in `yourplugin/templates/woocommerce/checkout`, wp-template will replace it.

```
use ODS\Template;
$template = new Template( plugin_dir_path( __FILE__ ) . 'templates/' );
$template->add_woocommerce();
```

Credits
-------

[](#credits)

The `add_page()` method was adapted from

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

7

Last Release

1679d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1587136?v=4)[Oberon Lai](/maintainers/oberonlai)[@oberonlai](https://github.com/oberonlai)

---

Top Contributors

[![oberonlai](https://avatars.githubusercontent.com/u/1587136?v=4)](https://github.com/oberonlai "oberonlai (10 commits)")

### Embed Badge

![Health badge](/badges/oberonlai-wp-template/health.svg)

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

###  Alternatives

[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3851.2M](/packages/limenius-react-bundle)[area17/laravel-auto-head-tags

Laravel Auto Head Tags helps you build the list of head elements for your app

4616.1k](/packages/area17-laravel-auto-head-tags)[jelix/wikirenderer

WikiRenderer is a library to generate HTML or anything else from wiki content.

1712.3k1](/packages/jelix-wikirenderer)[webkinder/sproutset

A Composer package for handling responsive images in Roots Bedrock + Sage + Blade projects.

282.2k](/packages/webkinder-sproutset)

PHPackages © 2026

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