PHPackages                             jacksleight/statamic-focal-link - 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. jacksleight/statamic-focal-link

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

jacksleight/statamic-focal-link
===============================

2.0.2(2y ago)397PHP

Since Nov 16Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/jacksleight/statamic-focal-link)[ Packagist](https://packagist.org/packages/jacksleight/statamic-focal-link)[ RSS](/packages/jacksleight-statamic-focal-link/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

Focal Link Fieldtype
====================

[](#focal-link-fieldtype)

> ⚠️ **Abandoned**

This Statamic addon simplifies linking to URL hashes (fragment identifiers) by automatically discovering IDs in the destination page and providing templates for common formats. Also supports fixed options, manual input and query strings.

Automatic discovery works by scanning the destination page for IDs and allowing you to select one from a list. You can control exactly which IDs are discovered using XPath expressions. Templates work by prompting the user for a value and then automatically URL encoding it.

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

[](#installation)

You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root:

```
composer require jacksleight/statamic-focal-link
```

Configuration
-------------

[](#configuration)

The default configuration comes with a couple of examples to get you started, but as every site is different you'll need to tell it what to enable and how for best results. To do this publish the config:

```
php please vendor:publish --tag=statamic-focal-link-config
```

And then open `config/statamic/focal_link.php`.

Getting Started
---------------

[](#getting-started)

Each key in the `types` list should be a pattern that matches a type of link. These can contain asterisks to perform wildcard matches. They should be in order of specificity (lowest to highest), the most specific match wins.

- URL link types use the pattern: `[protocol][host][port?][path]`
    - Basically the full URL up to the end of the path
    - `http(s)` and `www` will be normalized automatically
- Entry link types use the pattern: `entry::[collection]::[blueprint]`
- Asset link types use the pattern: `asset::[container]::[mime-type]`

Each type can contain the following settings:

- **discovery:** A value/label array of XPath expressions used to find IDs in the destination page
- **fragments:** A value/label array of fragment identifier options or templates
- **queries:** A value/label array of query string options or templates

If **fragments** or **queries** are excluded those fields will not appear at all.

### Fragment &amp; Query Options

[](#fragment--query-options)

Options can either be a fixed value or a template value. Templates must contain the string `{{ [placeholder] }}`, this where the cursor will be placed when the template is selected.

### ID Discovery

[](#id-discovery)

You can enable automatic ID discovery by setting the `discovery` option to an array of XPath expressions, these will be used to find matching elements in the destination page.

The key should be the path to the elements containing the ID attribute, the value should be the path to the node that contains the label, relative to the element. If the label expression is not set or the node cannot be found a label will be generated from the ID using `Str::headline()`.

### Example Link Type Settings

[](#example-link-type-settings)

```
'entry::products::*' => [ // All entries within the products collection

    'discovery' => [
        "//*[@id]" => "text()", // Elements with an ID attribute, with the text content as a label
    ],

    'fragments' => [
        "reviews" => "Reviews" // A fixed option
        ":~:text={{ text }}" => "Text Fragment", // A template option
    ],

    'queries' => [
        "size=large" => "Size — Large" // A fixed option
        "size={{ medium }}" => "Size" // A template option
    ],

],
```

Check out the [examples](https://github.com/jacksleight/statamic-focal-link/blob/main/resources/data/examples.php) and [included template presets](https://github.com/jacksleight/statamic-focal-link/blob/main/resources/data/presets.php) for more examples.

> **Warning:** If you enable discovery on external sites bear in mind that site design changes may invalidate the XPath expressions you write.

Fieldtype Options
-----------------

[](#fieldtype-options)

- **collections:** The collections that should be linkable

Automatic Heading IDs
---------------------

[](#automatic-heading-ids)

**Shameless Plug:** You can use my [Bard Mutator](https://statamic.com/addons/jacksleight/bard-mutator) addon to automatically apply IDs to heading elements rendered by the Bard fieldtype, and then use this addon to link directly to them. Here's the mutator function you'll need:

```
use JackSleight\StatamicBardMutator\Facades\Mutator;

Mutator::tag('heading', function ($tag, $data) {
    $tag[0]['attrs']['id'] = str_slug(collect($data->content)->implode('text', ''));
    return $tag;
});
```

Popular Site Template Presets
-----------------------------

[](#popular-site-template-presets)

The addon comes with a [couple of template presets](https://github.com/jacksleight/statamic-focal-link/blob/main/resources/data/presets.php) for popular sites. If you know of others and would like them added feel free to submit an issue or PR.

Link Fieldtype Compatibility
----------------------------

[](#link-fieldtype-compatibility)

This fieldtype tries to work as seamlessly as possible with the built-in Link fieldtype, by wrapping a Link field and then bolting on the additional features. Depending on the link this either stores values in an identical format or a suffixed format.

Any Link field can be changed to a Focal Link field and the values will be compatible. However if you change a Focal Link field back to a Link field Entry values with a query or fragment set will not be compatible, the suffixes will need to be removed.

Licencing
---------

[](#licencing)

Statamic Focal Link is not free software. You will need to purchase a license via the [Statamic Marketplace](https://statamic.com/addons/jacksleight/focal-link) to use it in production.

Contributing
------------

[](#contributing)

Contributions are very welcome, however please bear in mind that while Focal Link's source code is open source and publicly available, it is proprietary. Everything in this repo, including any community-contributed code, is the property of Jack Sleight.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance51

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~112 days

Recently: every ~224 days

Total

9

Last Release

732d ago

Major Versions

0.2.3 → 1.0.02022-05-31

1.0.0 → 2.0.02023-05-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b1acb404d9801e5f633e31efa3403a4735e43ea93c798e3f895ba3264c92c6e?d=identicon)[jacksleight](/maintainers/jacksleight)

---

Top Contributors

[![jacksleight](https://avatars.githubusercontent.com/u/126740?v=4)](https://github.com/jacksleight "jacksleight (86 commits)")

### Embed Badge

![Health badge](/badges/jacksleight-statamic-focal-link/health.svg)

```
[![Health](https://phpackages.com/badges/jacksleight-statamic-focal-link/health.svg)](https://phpackages.com/packages/jacksleight-statamic-focal-link)
```

###  Alternatives

[statamic/seo-pro

65440.7k](/packages/statamic-seo-pro)[jacksleight/statamic-bard-texstyle

17172.5k](/packages/jacksleight-statamic-bard-texstyle)[marcorieser/statamic-livewire

A Laravel Livewire integration for Statamic.

2381.5k10](/packages/marcorieser-statamic-livewire)[withcandour/aardvark-seo

Save time and get your Statamic site to rank better with the SEO addon for Statamic.

13128.3k](/packages/withcandour-aardvark-seo)[alt-design/alt-sitemap

Alt Sitemap addon, create a sitemap from Statamic entries

1219.0k](/packages/alt-design-alt-sitemap)[studio1902/statamic-peak-tools

11146.7k](/packages/studio1902-statamic-peak-tools)

PHPackages © 2026

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