PHPackages                             webwizo/laravel-shortcodes - 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. webwizo/laravel-shortcodes

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

webwizo/laravel-shortcodes
==========================

Wordpress like shortcodes for Laravel 11, 12 and 13

v1.0.33(1w ago)217700.9k↓30.8%53[4 issues](https://github.com/webwizo/laravel-shortcodes/issues)7MITPHPPHP ^8.2CI passing

Since May 24Pushed 1w ago8 watchersCompare

[ Source](https://github.com/webwizo/laravel-shortcodes)[ Packagist](https://packagist.org/packages/webwizo/laravel-shortcodes)[ Docs](https://github.com/webwizo/laravel-shortcodes)[ RSS](/packages/webwizo-laravel-shortcodes/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (25)Versions (34)Used By (7)

Laravel-Shortcodes
==================

[](#laravel-shortcodes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8d4850c89b9f291dba3835aac5140c99e2a0bba3ed22ca52b3b59ebf918cfaf0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77656277697a6f2f6c61726176656c2d73686f7274636f6465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webwizo/laravel-shortcodes)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Coverage Status](https://camo.githubusercontent.com/a16874aedd7c71347eb8f6d53ad8fb78f907fcd5cdb5865775f3d1d4586e6e51/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f77656277697a6f2f6c61726176656c2d73686f7274636f6465732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/webwizo/laravel-shortcodes/code-structure)[![Quality Score](https://camo.githubusercontent.com/9b0de99eb0b8d494e06472bfe69a30b8565545e3f9bb9250eb48d32a36a0d21f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f77656277697a6f2f6c61726176656c2d73686f7274636f6465732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/webwizo/laravel-shortcodes)[![Total Downloads](https://camo.githubusercontent.com/19b933237a597968ddca3008fc31bc645137422c9cac164021ea24b561235586/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656277697a6f2f6c61726176656c2d73686f7274636f6465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webwizo/laravel-shortcodes)

WordPress-like shortcodes for **Laravel 11, 12, and 13** (PHP 8.2+).
--------------------------------------------------------------------

[](#wordpress-like-shortcodes-for-laravel-11-12-and-13-php-82)

[![Laravel Shortcodes](https://github.com/webwizo/laravel-shortcodes/raw/master/preview.png?raw=true)](https://github.com/webwizo/laravel-shortcodes/blob/master/preview.png?raw=true)

**Documentation last updated:** 2026-04-22

```
[b class="bold"]Bold text[/b]

[tabs]
  [tab]Tab 1[/tab]
  [tab]Tab 2[/tab]
[/tabs]

[user id="1" display="name"]
```

If you are looking for Laravel 4.2, see:

Install
-------

[](#install)

Via Composer:

```
composer require webwizo/laravel-shortcodes
```

Laravel 11+ discovers the package automatically. On older setups, register `Webwizo\Shortcodes\ShortcodesServiceProvider` in `config/app.php` (or `bootstrap/providers.php` where applicable).

### Service provider (manual registration)

[](#service-provider-manual-registration)

```
Webwizo\Shortcodes\ShortcodesServiceProvider::class,
```

You can use the facade for shorter code. Add this to your aliases (optional):

```
'Shortcode' => Webwizo\Shortcodes\Facades\Shortcode::class,
```

The class is bound to the ioC as `shortcode`

```
$shortcode = app('shortcode');
```

Usage
-----

[](#usage)

### withShortcodes()

[](#withshortcodes)

To enable the view compiling features:

```
return view('view')->withShortcodes();
```

This will enable shortcode rendering for that view only.

### withShortcodes() in Mailables

[](#withshortcodes-in-mailables)

You can also enable shortcode compilation for a mailable view:

Available since: `v1.0.31`

```
use Illuminate\Mail\Mailable;

class NewsletterMail extends Mailable
{
    public function build()
    {
        return $this
            ->subject('Weekly newsletter')
            ->view('emails.newsletter', [
                'content' => 'Mail content',
            ])
            ->withShortcodes();
    }
}
```

`emails/newsletter.blade.php`

```
[b class="mail"]{{ $content }}[/b]
```

The shortcode tags in that mailable view will be compiled during rendering.

### Enable through class

[](#enable-through-class)

```
Shortcode::enable();
```

### Disable through class

[](#disable-through-class)

```
Shortcode::disable();
```

### Disabling some views from shortcode compiling

[](#disabling-some-views-from-shortcode-compiling)

With the config set to true, you can disable the compiling per view.

```
return view('view')->withoutShortcodes();
```

Default compiling
-----------------

[](#default-compiling)

To use default compiling:

```
Shortcode::compile($contents);
```

### Strip shortcodes from rendered view.

[](#strip-shortcodes-from-rendered-view)

```
return view('view')->withStripShortcodes();
```

Strip shortcode through class
-----------------------------

[](#strip-shortcode-through-class)

```
Shortcode::strip($contents);
```

Shortcode syntax and parser
---------------------------

[](#shortcode-syntax-and-parser)

The compiler scans templates left to right. Behaviour relevant to authoring tags:

TopicBehaviour**Attributes**Quoted values may contain spaces. Keys may include hyphens (e.g. `data-size="large"`). Parsing follows the same general rules as WordPress shortcode attributes.**Void / self-closing**A tag such as `[alert type="info"]` with **no** matching `[/alert]` is treated as self-closing (no inner body). Use explicit `[/tag]` when you need wrapping content.**Nested same-name tags**Nested tags with the **same** name (e.g. `[div]…[div]…[/div]…[/div]`) are matched using balanced opening/closing pairs, innermost structure preserved.**Unknown `[` text**Text in square brackets that does **not** start with a registered shortcode name is left unchanged (so prose like `[I agree …]` is not eaten).**Escaping**Use doubled brackets to output a literal shortcode: `[[b]]` → `[b]`.PHPUnit regression tests for these cases live under `tests/GitHubIssue*.php`.

Registering new shortcodes
--------------------------

[](#registering-new-shortcodes)

Create a new ServiceProvider where you can register all the shortcodes.

```
php artisan make:provider ShortcodesServiceProvider
```

After defining shortcodes, add the ServiceProvider to the providers array in `config/app.php` (or `bootstrap/providers.php`).

### Example: register your shortcodes provider

[](#example-register-your-shortcodes-provider)

```
App\Providers\ShortcodesServiceProvider::class,
```

### Callback

[](#callback)

Shortcodes can be registered within ShortcodesServiceProvider with a callback:

```
php artisan make:provider ShortcodesServiceProvider
```

ShortcodesServiceProvider.php Class File

```
