PHPackages                             pauloamgomes/cockpitcms-betterslugs - 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. [API Development](/categories/api)
4. /
5. pauloamgomes/cockpitcms-betterslugs

AbandonedArchivedCockpit-module[API Development](/categories/api)

pauloamgomes/cockpitcms-betterslugs
===================================

Better slugs Addon for Cockpit CMS, provides a new slug field type.

v1.0.0(5y ago)20364[2 issues](https://github.com/pauloamgomes/CockpitCMS-BetterSlugs/issues)MITPHPPHP &gt;= 7.3

Since Feb 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/pauloamgomes/CockpitCMS-BetterSlugs)[ Packagist](https://packagist.org/packages/pauloamgomes/cockpitcms-betterslugs)[ Docs](https://github.com/pauloamgomes/CockpitCMS-BetterSlugs)[ RSS](/packages/pauloamgomes-cockpitcms-betterslugs/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Better Slugs Addon for Cockpit CMS
==================================

[](#better-slugs-addon-for-cockpit-cms)

This addon enhances Cockpit CMS by providing a slug field type that can be used to generate automatically slugs for your collections. Tokens are supported in order to dynamically set values (e.g. dates, fields, etc..).

Idea was partially taken by the Unique Slugs addon [https://github.com/raffaelj/cockpit\_UniqueSlugs](https://github.com/raffaelj/cockpit_UniqueSlugs)

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

[](#installation)

### Manual

[](#manual)

Download [latest release](https://github.com/pauloamgomes/CockpitCMS-BetterSlugs) and extract to `COCKPIT_PATH/addons/BetterSlugs` directory

### Git

[](#git)

```
git clone https://github.com/pauloamgomes/CockpitCMS-BetterSlugs.git ./addons/BetterSlugs
```

### Cockpit CLI

[](#cockpit-cli)

```
php ./cp install/addon --name BetterSlugs --url https://github.com/pauloamgomes/CockpitCMS-BetterSlugs.git
```

### Composer

[](#composer)

1. Make sure path to cockpit addons is defined in your projects' *composer.json* file:

```
{
    "name": "MY_PROJECT",
    "extra": {
        "installer-paths": {
            "cockpit/addons/{$name}": ["type:cockpit-module"]
        }
    }
}
```

2. In your project root run:

```
composer require pauloamgomes/cockpitcms-betterslugs
```

---

Usage
-----

[](#usage)

Add a new field of type slug to your collection and configure a format, e.g:

```
{
  "format": "[collection:name]/[date:Y]/[field:title]"
}
```

For a collection named post it will result in something like `post/2019/your-post-title`, if you want to start with `/` like `/post/2019/your-post-title` use:

```
{
  "format": "/[collection:name]/[date:Y]/[field:title]"
}
```

You can also use static values in the slug e.g. starting with `blogs` like `blogs/2019/01/your-post-title`:

```
{
  "format": "blogs/[date:Y]/[date:m]/[field:title]"
}
```

If you are using localization and want to have your slug prefixed with the corresponding language id like `en/post/2019/your-post-title`

```
{
  "format": "[lang:id]/blogs/[date:Y]/[date:m]/[field:title]"
}
```

And using a custom callback function:

```
{
  "format": "blogs/[callback:slugUniqId]/[field:title]"
}
```

Assuming you have the slugUniqId function (e.g. in a boostrap.php addon file):

```
function slugUniqId($entry, $app, $lang = FALSE) {
  return uniqid();
}
```

it will return in something like `blogs/5c2ccc816619b/your-post-title`

The callback function receives the $entry array as argument.

Currently the following tokens are supported:

- collection:value - where value is present in the collection structure (e.g. name)
- date:value - where value is any valid php date char (e.g. Y, m, d, YMD, etc..)
- field:value - where value is the field name (e.g. title)
- lang:id - replaces token with language id (e.g. en, fr, pt, etc..)
- linkedField:value|param - where value is the linked field collection name and param is the value from the linked collection, e.g.:

```
"format": "countries/[linkedField:country|name]]/[field:title]"
```

If we have a field named country that is a collection link, it will retrieve the collection link entry values and extract the name field, so it would result in something like: `countries/netherlands/my-title`

- callback:value - where value is a custom callback function

By default the generated slugs are unique, so if you have a slug field configured with format:

```
"format": "blogs/[date:Y]/[date:m]/[field:title]"
```

and your field title is "Blog Test" `blogs/2019/01/blog-test`, if you insert another entry with same title it will result on `blogs/2019/01/blog-test-1`, and next one on `blogs/2019/01/blog-test-2`.

The slug is only autogenerated when the field value is empty, so it can be overriden by the user with a non generated value.

Localization is supported, just enable in the field definition and the corresponding field language names (e.g. slug, slug\_en, slug\_pt) will be automatically populated.

A CLI command can be used to update all slugs in a collection:

```
$ ./cp refresh-slugs --name  blog_post

Collection 'blog_post' - Refreshing slugs...
Slug for 5c2cbece164bfc004d0b7595 updated to 'blogs/2019/01/test'
Slug for 5c2cbf82164bfc0044192afc updated to 'blogs/2019/01/test-1'
Slug for 5c2cbfaf164bfc00455447b4 updated to 'blogs/2019/01/test-2'
Slug for 5c2cc22a164bfc00455447b7 updated to 'blogs/2019/01/another-post'
Slug for 5c2ccc81164bfc00455447b9 updated to 'blogs/2019/01/testing-callback'
Done! 9 entries updated in 0.032s
```

Copyright and license
---------------------

[](#copyright-and-license)

Copyright 2019 pauloamgomes under the MIT license.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

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

1974d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e5d76b00c52f0e92746848bda311bf68308c6ecfb1207871504c9814cde6d9b5?d=identicon)[pauloamgomes](/maintainers/pauloamgomes)

---

Top Contributors

[![pauloamgomes](https://avatars.githubusercontent.com/u/102261?v=4)](https://github.com/pauloamgomes "pauloamgomes (14 commits)")[![Raruto](https://avatars.githubusercontent.com/u/9614886?v=4)](https://github.com/Raruto "Raruto (3 commits)")[![jasonday](https://avatars.githubusercontent.com/u/748011?v=4)](https://github.com/jasonday "jasonday (1 commits)")

---

Tags

cockpit-cmscockpit-cms-addonslugs-addonapicockpitcmsheadlessslugs-addon

### Embed Badge

![Health badge](/badges/pauloamgomes-cockpitcms-betterslugs/health.svg)

```
[![Health](https://phpackages.com/badges/pauloamgomes-cockpitcms-betterslugs/health.svg)](https://phpackages.com/packages/pauloamgomes-cockpitcms-betterslugs)
```

###  Alternatives

[aheinze/cockpit

Cockpit Headless CMS

5.4k2.0k4](/packages/aheinze-cockpit)[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.5k10](/packages/helsingborg-stad-municipio)[october/rain

October Rain Library

1601.7M83](/packages/october-rain)[getkirby/kql

Kirby Query Language

15027.0k](/packages/getkirby-kql)[aimeos/aimeos-headless

Aimeos headless ecommerce system

2.5k2.3k](/packages/aimeos-aimeos-headless)

PHPackages © 2026

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