superbig/craft3-shortcut

Simple URL shortening

Fund package maintenance!
verbb

Installs: 6 514

Dependents: 0

Suggesters: 0

Security: 0

Stars: 10

Watchers: 4

Forks: 2

Type:craft-plugin

4.0.0 2022-07-19 02:30 UTC

This package is auto-updated.

Last update: 2022-10-29 02:26:39 UTC


README

Lets you create short links for elements or arbitrary URLs.

Installation

You can install Shortcut via the plugin store, or through Composer.

Craft Plugin Store

To install Shortcut, navigate to the Plugin Store section of your Craft control panel, search for Shortcut, and click the Try button.

Composer

You can also add the package to your project using Composer and the command line.

  1. Open your terminal and go to your Craft project:
cd /path/to/project
  1. Then tell Composer to require the plugin, and Craft to install it:
composer require verbb/shortcut && php craft plugin/install shortcut

Usage

To create a short url for an element:

{% set shortcut = craft.shortcut.get({ element: entry }) %}

{{ shortcut.getUrl() }}

To create a short url for a url:

{% set shortcut = craft.shortcut.get({ url: 'https://cnn.com' }) %}

{{ shortcut.getUrl() }}

By default, short urls is in the format xxxx.tld/s/aBC123. If you want to change the url segment from s to something custom, you can add a config file called shortcut.php in craft/config to override it:

<?php
return [
    // Override Shortcut URL segment
    'urlSegment' => 'x',
];

If you want to remove the url segment completely and get urls like xxxx.tld/aBC123, you can enable the hideUrlSegment option.

<?php
return [
    // Hide url segment
    'hideUrlSegment' => true,
];

To use a custom domain, add the domain with the customDomain option.

<?php
return [
    // Set custom domain
    'customDomain' => 'https://cool.domain',
];

You can also control the length of the unique hash generated using the hashLength option.

<?php
return [
    // Set the hash length
    'hashLength' => 12,
];

Credits

Originally created by the team at Superbig.

Show your Support

Shortcut is licensed under the MIT license, meaning it will always be free and open source – we love free stuff! If you'd like to show your support to the plugin regardless, Sponsor development.

68747470733a2f2f76657262622e696f2f6173736574732f696d672f76657262622d70696c6c2e737667