PHPackages                             unprefix/unprefix-twig-wordpress - 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. unprefix/unprefix-twig-wordpress

Abandoned → [twigwp/twig-wordpress](/?search=twigwp%2Ftwig-wordpress)Library[Templating &amp; Views](/categories/templating)

unprefix/unprefix-twig-wordpress
================================

Twig for WordPress as Service

1.4.1(7y ago)5186[8 issues](https://github.com/widoz/twig-wordpress/issues)GPL-2.0-onlyPHPPHP &gt;=7.0CI failing

Since Mar 4Pushed 7y ago2 watchersCompare

[ Source](https://github.com/widoz/twig-wordpress)[ Packagist](https://packagist.org/packages/unprefix/unprefix-twig-wordpress)[ Docs](https://github.com/widoz/twig-wordpress)[ RSS](/packages/unprefix-unprefix-twig-wordpress/feed)WikiDiscussions develop Synced 2mo ago

READMEChangelog (5)Dependencies (4)Versions (10)Used By (0)

[![Build Status](https://camo.githubusercontent.com/36876024c94cfc98e0c10938043bd881cd72ef51a088f33cf454978b653d6a7f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7769646f7a2f747769672d776f726470726573732f646576656c6f702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/widoz/twig-wordpress)[![codecov](https://camo.githubusercontent.com/2ad0ba5b617ba2dc02f7389c78c0c1872e1e3d69bde30639ca046f0f2312020c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f7769646f7a2f747769672d776f726470726573732f646576656c6f702e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/widoz/twig-wordpress)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2335b23487eca9c9d93359f8d8f7afb0dacfe3e9b8e3886f36b17b051a1583d6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7769646f7a2f747769672d776f726470726573732f646576656c6f702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/widoz/twig-wordpress/?branch=develop)

Twig for WordPress
==================

[](#twig-for-wordpress)

Twig for WordPress allow you to use the famous Twig template engine but extend it to be able to use the functions provided by WordPress such as `esc_html`, `esc_html__`, `wp_kses` etc...

This package register the escape function as filters and functions because translator functions need to be pass a textdomain.

Modules
-------

[](#modules)

The package provide filters, functions and other stuffs into twig by define `modules`.

Modules are class instances that implements an interface `TwigWp\Module\Injectable` used by the Provider `TwigWp\Module\Provider` that allow us to retrieve all modules to be set into `twig` instance.

There is a filter `twigwp.modules` within the `Provider::modules` method that allow third party softwares to hook into the modules list so, they'll be able to add other filters, functions, tags or whatever they want to use to extend the twig instance (read about how to extend twig here ).

### Escapers

[](#escapers)

Twig for WordPress define as filters and functions the followings:

- esc\_js
- esc\_sql
- esc\_textarea
- esc\_url
- esc\_url\_raw
- esc\_attr
- esc\_html

### Kses

[](#kses)

The kses are defined only as functions.

- wp\_kses
- wp\_kses\_post
- wp\_kses\_allowed\_html

### Sanitizers

[](#sanitizers)

The sanitizers are defined only as functions.

- sanitize\_html\_class
- sanitize\_text\_field
- sanitize\_title
- sanitize\_key

### L10n

[](#l10n)

Localization functions, including the escaped ones. Localizations functions that start with `esc_` (escape) are also registered as filters.

- \_\_
- \_e
- \_n
- \_x
- \_ex
- \_nx
- esc\_attr\_\_
- esc\_attr\_e
- esc\_attr\_x
- esc\_html\_\_
- esc\_html\_e
- esc\_html\_x

### Template Functions

[](#template-functions)

This module include all of the functions that echo html markup even if them are not WordPress template functions.

This because most of the WordPress functions usually get some configuration by array and output html markup. Having to put in a object property the entire markup isn't usefull since you want to have your markup into your views, these functions will help you to pass the configuration and call the output function directly, avoiding to permit to parse html markup that may result in a unescaped html.

- wp\_nav\_menu
- get\_adjacent\_post\_link

Provider
--------

[](#provider)

The modules are retrieved by a Provider.

Within the provider the modules can be filtered `twigwp.modules`.

So if you want to add a new module you can hook into this filter and return a new instance of `TwigWp\Module\Injectable`.

A Module is used to extend the twig instance, the method `injectInto` get a `\Twig\Environment` instance to use for example to add a new function, a new filter or a new tag etc...

For example:

```
class MyModule implements TwigWp\Module\Injectable {

	public function injectInto(\Twig\Environment $twig): \Twig\Environment {
		// Do your stuffs here.

		return $twig;
	}

}

$provider = new Provider(new \Twig\Environmnet());

add_filter('twigwp.modules', function($modules)
{
	$modules['module_name'] = new MyModule();

	return $modules;
});

$modules = $provider->modules();
```

This is just an example because you'll never need to create an instance of the Module `Provider`. Everything is handled by the `Factory` class.

You just need to add your filter and everything is ok.

Factory
-------

[](#factory)

The package provide a `Factory` class that help you on creating a new instance of the `\Twig\Environment` class.

If you want to create a new Twig instance you can simply create a factory instance by passing a `\Twig\Loader\LoaderInterface` object and the twig options if you want to customize the environment.

Then call the `create` method and you've done.

```
$twigFactory = new \TwigWp\Factory(
	new \Twig\Loader\FilesystemLoader(),
	[
        'debug' => false,
        'charset' => 'UTF-8',
        'base_template_class' => 'Twig_Template',
        'strict_variables' => false,
        'autoescape' => 'html',
        'cache' => false,
        'auto_reload' => null,
        'optimizations' => -1,
	]
);

$twig = $twigFactory->create();
```

Pretty easy, right?

License
-------

[](#license)

This programm is free software and is licensed using GPL2.

For more info about the license see

Requirements
------------

[](#requirements)

PHP &gt;= 7.0

Bugs Reporting
--------------

[](#bugs-reporting)

To report bugs please refer to

Support
-------

[](#support)

For support just open a new issue  and apply the label `help wanted`.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 97.9% 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 ~41 days

Recently: every ~33 days

Total

8

Last Release

2702d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d39b8d5cede59a2123551e756824be76d75405fab12f4e553be05328e9b1341?d=identicon)[guido](/maintainers/guido)

---

Top Contributors

[![widoz](https://avatars.githubusercontent.com/u/1917784?v=4)](https://github.com/widoz "widoz (46 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

templatetemplate-enginetwigunit-testedwordpresspsrcomposerwordpresstwig

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/unprefix-unprefix-twig-wordpress/health.svg)

```
[![Health](https://phpackages.com/badges/unprefix-unprefix-twig-wordpress/health.svg)](https://phpackages.com/packages/unprefix-unprefix-twig-wordpress)
```

###  Alternatives

[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.4M108](/packages/timber-timber)[symfony/ux-twig-component

Twig components for Symfony

21814.8M161](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1635.6M71](/packages/symfony-ux-live-component)[twig/html-extra

A Twig extension for HTML

777.6M41](/packages/twig-html-extra)[frozzare/digster

Twig templates for WordPress

107.1k](/packages/frozzare-digster)

PHPackages © 2026

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