PHPackages                             kaiseki/wp-html-attributes - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. kaiseki/wp-html-attributes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kaiseki/wp-html-attributes
==========================

Fluent builder for composing, merging and rendering escaped HTML element attributes in WordPress

1.0.0(1mo ago)0506MITPHPPHP ^8.2CI passing

Since Jun 1Pushed 3w ago2 watchersCompare

[ Source](https://github.com/kaisekidev/kaiseki-wp-html-attributes)[ Packagist](https://packagist.org/packages/kaiseki/wp-html-attributes)[ Docs](https://github.com/kaisekidev/kaiseki-wp-html-attributes)[ RSS](/packages/kaiseki-wp-html-attributes/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (14)Versions (3)Used By (0)

kaiseki/wp-html-attributes
==========================

[](#kaisekiwp-html-attributes)

Fluent builder for composing, merging and rendering escaped HTML element attributes in WordPress.

Attributes are collected through a small chainable API, classes are merged and de-duplicated rather than overwritten, and the rendered output is escaped with WordPress' own `esc_attr()` / `esc_url()`and emitted in a stable, predictable order.

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

[](#installation)

```
composer require kaiseki/wp-html-attributes
```

Requires PHP 8.2 or newer.

Usage
-----

[](#usage)

```
use Kaiseki\WordPress\HtmlAttributes\HtmlAttributes;

$attributes = HtmlAttributes::create(['id' => 'cta'])
    ->addClass('button', 'button--primary')
    ->addAttribute('href', 'https://example.com')
    ->addAttribute('target', '_blank');

echo 'Read more';
// Read more
```

### Building attributes

[](#building-attributes)

- `HtmlAttributes::create(?array $attributes = [])` / `new HtmlAttributes(?array $attributes = [])` — start from an optional `name => value` map.
- `addAttribute(string $name, string $value, bool $merge = true)` — set a single attribute. With `$merge` (the default) a `class` value is merged into the existing classes; pass `false` to replace.
- `addAttributes(array $attributes, bool $merge = true)` — set several at once.
- `addClass(string ...$class)` — add one or more class names; each argument may itself be a space-separated list. Duplicates are removed on render.
- `getAttribute(string $name)` / `getAttributes()` — read back the current state.

### Rendering

[](#rendering)

`renderAttributes(array $attributes = [])` returns the escaped attribute string (any attributes passed are merged in first):

- `href` values are escaped with `esc_url()` (the `fb-messenger` protocol is allowed in addition to WordPress' defaults); every other value is escaped with `esc_attr()`.
- Empty `href`, `class`, `target` and `rel` values are omitted.
- Output is ordered `id`, `href`, `target`, `rel`, `class`, then any remaining attributes alphabetically.

### Reusing the builder in your own class

[](#reusing-the-builder-in-your-own-class)

The behaviour lives in `HtmlAttributesTrait`, so a class that maintains its own `array $attributes` can `use HtmlAttributesTrait;` to gain the same API.

Development
-----------

[](#development)

```
composer install
composer check   # check-deps, cs-check, phpstan
```

License
-------

[](#license)

MIT — see [LICENSE](LICENSE.md).

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance95

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 70% 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

Unknown

Total

1

Last Release

32d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c3a6b11aea9668c9e9ca0c0f8515ef114d344acb552c695d715d35d5b388ea4?d=identicon)[woda](/maintainers/woda)

---

Top Contributors

[![wolfgangschaefer](https://avatars.githubusercontent.com/u/26325205?v=4)](https://github.com/wolfgangschaefer "wolfgangschaefer (7 commits)")[![davidmondok](https://avatars.githubusercontent.com/u/3883758?v=4)](https://github.com/davidmondok "davidmondok (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kaiseki-wp-html-attributes/health.svg)

```
[![Health](https://phpackages.com/badges/kaiseki-wp-html-attributes/health.svg)](https://phpackages.com/packages/kaiseki-wp-html-attributes)
```

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k455.6M9.6k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

706130.3M13.3k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31182.0M2.4k](/packages/illuminate-container)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k51](/packages/ecotone-ecotone)[symfony/type-info

Extracts PHP types information.

20069.8M269](/packages/symfony-type-info)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)

PHPackages © 2026

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