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

ActiveLibrary

vedmant/laravel-shortcodes
==========================

Wordress like shortcodes for Laravel

1.1.2(3y ago)2811.2k—10%51MITPHPPHP &gt;=7.0.0

Since Apr 20Pushed 3y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (27)Used By (1)

Laravel Shortcodes
==================

[](#laravel-shortcodes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/91db1c33d6a15bb1dcfe4648f9eb1d4b004ecb2e809d288f69d7af7009f8bbe4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7665646d616e742f6c61726176656c2d73686f7274636f6465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vedmant/laravel-shortcodes)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)[![Total Downloads](https://camo.githubusercontent.com/b7ac6ea58b3ea1a50bf8dc40e55bf7842e1ad50fb7deb5c98fa18d1b135788da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7665646d616e742f6c61726176656c2d73686f7274636f6465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vedmant/laravel-shortcodes)[![Tests](https://github.com/vedmant/laravel-shortcodes/actions/workflows/tests.yml/badge.svg)](https://github.com/vedmant/laravel-shortcodes/actions/workflows/tests.yml/badge.svg)[![StyleCI](https://camo.githubusercontent.com/b04255544ade1996e52592d408f1af9b45fdf75c06c8a768340ac0f19ad19dfc/68747470733a2f2f7374796c6563692e696f2f7265706f732f3138323237363034312f736869656c64)](https://styleci.io/repos/182276041)

Wordpress based Shortcodes for [Laravel Framework](https://github.com/laravel/laravel) with shared variables, debugbar integration, flexible configurations and other useful features.

Build powerful and simple layouts using shortcodes in the content or views like this:

```
[b]Bold text[/b]

[row]
  [col md=8]
    [posts_list types="post,gallery" show_tags="yes"]
  [/col]
  [col md=4]
    [poll id="1"]
    [user_info username="test_user" website="mywebsite.com" active="yes"]
    [last_free_post title="Free Posts"]
  [/col]
[/row]
```

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

[](#installation)

Via Composer

```
$ composer require vedmant/laravel-shortcodes
```

Configuraton
------------

[](#configuraton)

Publish configuration.

```
php artisan vendor:publish --tag=shortcodes
```

It will publish configuration file `shortcodes.php`, edit it as needed.

Usage
-----

[](#usage)

### Shortcode class

[](#shortcode-class)

Shortcode class should extend abstract \\Vedmant\\LaravelShortcodes\\Shortcode class.

This packages adds the `make:shortcode` artisan command:

```
php artisan make:shortcode PostsListShortcode
```

Which generates a shortcode class in the `app/Shortcodes` folder by default.

### Register shortcodes

[](#register-shortcodes)

You can use `AppServiceProvider::boot` method to register all needed shortcodes.

Using shortcode class:

```
Shortcodes::add('b', BShortcode::class);
```

Using shortcode classes in array, preferable for lots of shortcodes:

```
Shortcodes::add([
   'a' => AShortcode::class,
   'b' => BShortcode::class,
]);
```

Using closure:

```
Shortcodes::add('test', function ($atts, $content, $tag, $manager) {
   return new HtmlString('some test shortcode');
});
```

### Render shortcodes

[](#render-shortcodes)

#### Views auto-render

[](#views-auto-render)

By default this package extends the `View` class to parse all shortcodes during views rendering. This feature can be disabled in the config file: `'render_views' => false`. For better performance with lots of views it's advised to disable views auto-render.

#### Enable / disable rendering per view

[](#enable--disable-rendering-per-view)

Also to enable / disable rendering shortcodes for a specific view you can use:

```
view('some-view')->withShortcodes();
// Or
view('some-view')->withoutShortcodes();
```

#### Render shortcodes with the facade

[](#render-shortcodes-with-the-facade)

```
{{ Shortcodes::render('[b]bold[/b]') }}
```

#### Render shortcodes with blade directive

[](#render-shortcodes-with-blade-directive)

```
@shortcodes
   [b class="block"]Content[/b]
@endshortcodes

Or

@shortcodes('[b]bold[/b]')
```

#### Render shortcodes with `shortcodes()` helper

[](#render-shortcodes-with-shortcodes-helper)

```

   {{ shortcodes('[b]bold[/b]') }}

```

### Shared attributes

[](#shared-attributes)

Occasionally, you may need to share a piece of data with all shortcodes that are rendered by your application. You may do so using the shortode facade's `share` method. Typically, you should place calls to share in the controller, or within a service provider's boot method.

```
Shortcodes::share('post', $post);
```

Then you can get shared attributes in the shortcode class:

```
$post = $this->shared('post');
$allShared = $this->shared();
```

### Attribute casting

[](#attribute-casting)

The $casts property on your shortcode class provides a convenient method of converting attributes to common data types. The $casts property should be an array where the key is the name of the attribute being cast and the value is the type you wish to cast the column to. The supported cast types are: `int`, `integer`, `real`, `float`, `double`, `boolean`, `array` (comma separated values) and `date`.

```
class YourShortcode extends Shortcode
{
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'show_ids' => 'array',
    ];
}
```

Now the `show_ids` attribute will always be cast to an array when you access it. (array attributes are casted from comma separated string, eg. "1,2,3").

### Attribute validation

[](#attribute-validation)

There is a simple way to validate attributes. Error messages will be rendered on the shortcode place. For convenients it will return attributes.

```
class YourShortcode extends Shortcode
{
    /**
     * Render shortcode
     *
     * @param string $content
     * @return string
     */
    public function render($content)
    {
        $atts = $this->validate([
            'post_id' => 'required|numeric|exists:posts,id',
        ]);

        //
    }
}
```

### Option to not throw exceptions from shortcodes

[](#option-to-not-throw-exceptions-from-shortcodes)

There is a useful option to aviod server (500) error for whole page when one of shortocode has thrown an exception.

To enable it set `'throw_exceptions' => false,` in the `shortcodes.php` config file.

This will render exception details in the place of a shortcode and will not crash whole page request with 500 error. It will still log exception to a log file and report to [Sentry](https://sentry.io/) if it's integrated.

### Generate data for documentation

[](#generate-data-for-documentation)

There can be hundreds of registered shortcodes and having a way to show documentation for all shortcodes is quite a good feature. There is simple method that will collect descriptions and attributes data from all registered shortcodes:

```
$data = Shortcodes::registeredData();
```

It returns Collection object with generated data that can be used to generate any help information.

### Integration with Laravel Debugbar

[](#integration-with-laravel-debugbar)

This packages supports [Laravel Debugbar](https://github.com/barryvdh/laravel-debugbar)and adds a tab with detailed info about rendered shortcodes. Integration can be disabled in the config file with option: `'debugbar' => false,`.

Testing
-------

[](#testing)

```
$ vendor/bin/phpunit
```

TODO
----

[](#todo)

1. Add custom widget for debugbar integration
2. Create performance profile tests, optimize performance

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

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [All Contributors](../../contributors)

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 97.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

Every ~105 days

Recently: every ~316 days

Total

14

Last Release

1220d ago

PHP version history (2 changes)1.0.5PHP ^7.0.0

1.1.0PHP &gt;=7.0.0

### Community

Maintainers

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

---

Top Contributors

[![vedmant](https://avatars.githubusercontent.com/u/5052406?v=4)](https://github.com/vedmant "vedmant (87 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")[![zawarudo](https://avatars.githubusercontent.com/u/2955134?v=4)](https://github.com/zawarudo "zawarudo (1 commits)")

---

Tags

laravelshortcodeslaravelshortcodes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vedmant-laravel-shortcodes/health.svg)

```
[![Health](https://phpackages.com/badges/vedmant-laravel-shortcodes/health.svg)](https://phpackages.com/packages/vedmant-laravel-shortcodes)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[graham-campbell/markdown

Markdown Is A CommonMark Wrapper For Laravel

1.3k7.1M64](/packages/graham-campbell-markdown)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)

PHPackages © 2026

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