{"id":18035731,"url":"https://github.com/webwizo/laravel-shortcodes","last_synced_at":"2026-04-19T14:12:57.906Z","repository":{"id":39737525,"uuid":"59507292","full_name":"webwizo/laravel-shortcodes","owner":"webwizo","description":"Wordpress like shortcodes for Laravel 4.2, 5.x, 6.x, 7.x, 8.x, 9.x and 10.x","archived":false,"fork":false,"pushed_at":"2024-03-18T14:41:49.000Z","size":64,"stargazers_count":206,"open_issues_count":18,"forks_count":49,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-05-17T09:42:26.834Z","etag":null,"topics":["laravel","shortcode","wordpress"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webwizo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-23T18:13:35.000Z","updated_at":"2024-06-18T12:33:00.090Z","dependencies_parsed_at":"2024-03-18T16:11:47.867Z","dependency_job_id":null,"html_url":"https://github.com/webwizo/laravel-shortcodes","commit_stats":{"total_commits":73,"total_committers":19,"mean_commits":"3.8421052631578947","dds":0.5342465753424658,"last_synced_commit":"7c12bdb6ab139a0aaa28daf177d504b15cf5a8aa"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webwizo%2Flaravel-shortcodes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webwizo%2Flaravel-shortcodes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webwizo%2Flaravel-shortcodes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webwizo%2Flaravel-shortcodes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webwizo","download_url":"https://codeload.github.com/webwizo/laravel-shortcodes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535826,"owners_count":22087398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","shortcode","wordpress"],"created_at":"2024-10-30T12:09:22.867Z","updated_at":"2026-04-19T14:12:57.894Z","avatar_url":"https://github.com/webwizo.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/webwizo"],"categories":[],"sub_categories":[],"readme":"# Laravel-Shortcodes\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-travis]][link-travis]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![StyleCI](https://styleci.io/repos/59507292/shield)](https://styleci.io/repos/59507292)\n\nWordPress-like shortcodes for **Laravel 11, 12, and 13** (PHP 8.2+).\n\n**Documentation last updated:** 2026-04-19\n\n```php\n[b class=\"bold\"]Bold text[/b]\n\n[tabs]\n  [tab]Tab 1[/tab]\n  [tab]Tab 2[/tab]\n[/tabs]\n\n[user id=\"1\" display=\"name\"]\n```\n\nIf you are looking for Laravel 4.2, see: https://github.com/patrickbrouwers/Laravel-Shortcodes\n\n## Install\n\nVia Composer:\n\n```bash\ncomposer require webwizo/laravel-shortcodes\n```\n\nLaravel 11+ discovers the package automatically. On older setups, register `Webwizo\\Shortcodes\\ShortcodesServiceProvider` in `config/app.php` (or `bootstrap/providers.php` where applicable).\n\n### Service provider (manual registration)\n\n```php\nWebwizo\\Shortcodes\\ShortcodesServiceProvider::class,\n```\n\nYou can use the facade for shorter code. Add this to your aliases (optional):\n\n```php\n'Shortcode' =\u003e Webwizo\\Shortcodes\\Facades\\Shortcode::class,\n```\n\nThe class is bound to the ioC as `shortcode`\n\n```php\n$shortcode = app('shortcode');\n```\n\n## Usage\n\n### withShortcodes()\n\nTo enable the view compiling features:\n\n```php\nreturn view('view')-\u003ewithShortcodes();\n```\n\nThis will enable shortcode rendering for that view only.\n\n### Enable through class\n\n```php\nShortcode::enable();\n```\n\n### Disable through class\n\n```php\nShortcode::disable();\n```\n\n### Disabling some views from shortcode compiling\n\nWith the config set to true, you can disable the compiling per view.\n\n```php\nreturn view('view')-\u003ewithoutShortcodes();\n```\n\n## Default compiling\n\nTo use default compiling:\n\n```php\nShortcode::compile($contents);\n```\n\n### Strip shortcodes from rendered view.\n\n```php\nreturn view('view')-\u003ewithStripShortcodes();\n```\n\n## Strip shortcode through class\n\n```php\nShortcode::strip($contents);\n```\n\n## Shortcode syntax and parser\n\nThe compiler scans templates left to right. Behaviour relevant to authoring tags:\n\n| Topic | Behaviour |\n|--------|------------|\n| **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. |\n| **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. |\n| **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. |\n| **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). |\n| **Escaping** | Use doubled brackets to output a literal shortcode: `[[b]]` → `[b]`. |\n\nPHPUnit regression tests for these cases live under `tests/GitHubIssue*.php`.\n\n## Registering new shortcodes\n\nCreate a new ServiceProvider where you can register all the shortcodes.\n\n```bash\nphp artisan make:provider ShortcodesServiceProvider\n```\n\nAfter defining shortcodes, add the ServiceProvider to the providers array in `config/app.php` (or `bootstrap/providers.php`).\n\n### Example: register your shortcodes provider\n\n```php\nApp\\Providers\\ShortcodesServiceProvider::class,\n```\n\n### Callback\n\nShortcodes can be registered within ShortcodesServiceProvider with a callback:\n\n```bash\nphp artisan make:provider ShortcodesServiceProvider\n```\n\nShortcodesServiceProvider.php Class File\n\n```php\n\u003c?php namespace App\\Providers;\n\nuse App\\Shortcodes\\BoldShortcode;\nuse Illuminate\\Support\\ServiceProvider;\nuse Shortcode;\n\nclass ShortcodesServiceProvider extends ServiceProvider\n{\n    /**\n     * Bootstrap the application services.\n     *\n     * @return void\n     */\n    public function boot()\n    {\n        //\n    }\n\n    /**\n     * Register the application services.\n     *\n     * @return void\n     */\n    public function register()\n    {\n        Shortcode::register('b', BoldShortcode::class);\n        Shortcode::register('i', 'App\\Shortcodes\\ItalicShortcode@custom');\n    }\n}\n```\n\n### Default class for BoldShortcode\n\nYou can store each shortcode within their class `app/Shortcodes/BoldShortcode.php`\n\n```php\nnamespace App\\Shortcodes;\n\nclass BoldShortcode {\n\n  public function register($shortcode, $content, $compiler, $name, $viewData)\n  {\n    return sprintf('\u003cstrong class=\"%s\"\u003e%s\u003c/strong\u003e', $shortcode-\u003eclass, $content);\n  }\n\n}\n```\n\n### Class with custom method\n\nYou can store each shortcode within their class `app/Shortcodes/ItalicShortcode.php`\n\n```php\nnamespace App\\Shortcodes;\n\nclass ItalicShortcode {\n\n  public function custom($shortcode, $content, $compiler, $name, $viewData)\n  {\n    return sprintf('\u003ci class=\"%s\"\u003e%s\u003c/i\u003e', $shortcode-\u003eclass, $content);\n  }\n\n}\n```\n\n### Register helpers\n\nIf you only want to show the html attribute when the attribute is provided in the shortcode, you can use `$shortcode-\u003eget($attributeKey, $fallbackValue = null)`\n\n```php\nclass BoldShortcode {\n\n  public function register($shortcode, $content, $compiler, $name, $viewData)\n  {\n    return '\u003cstrong '. $shortcode-\u003eget('class', 'default') .'\u003e' . $content . '\u003c/strong\u003e';\n  }\n\n}\n```\n\n## Shortcode Artisan Generator Command\n\nThis package provides an Artisan command to quickly generate shortcode classes:\n\n```php\nphp artisan make:shortcode YourShortcodeName\n```\n\n-   By default, this creates a new class in `app/Shortcodes/YourShortcodeNameShortcode.php`.\n-   If the file already exists, use the `--force` option to overwrite:\n\n```bash\nphp artisan make:shortcode YourShortcodeName --force\n```\n\n### Customizing the Stub\n\nYou can publish the stub file to customize the generated class:\n\n```bash\nphp artisan vendor:publish --tag=shortcode-stubs\n```\n\nThis will copy the stub to `resources/stubs/shortcode.stub` in your Laravel app. Edit this file to change the template for new shortcode classes.\n\n## Testing\n\nFrom the package root (after `composer install`):\n\n```bash\ncomposer test\n# or\nvendor/bin/phpunit\n```\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email webwizo@gmail.com instead of using the issue tracker.\n\n## Credits\n\n-   [Asif Iqbal][link-author]\n-   [All Contributors][link-contributors]\n\n## Support me\n\n\u003ca href=\"https://www.buymeacoffee.com/webwizo\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;\" \u003e\u003c/a\u003e\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/webwizo/laravel-shortcodes.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/webwizo/laravel-shortcodes/master.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/webwizo/laravel-shortcodes.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/webwizo/laravel-shortcodes.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/webwizo/laravel-shortcodes.svg?style=flat-square\n[link-packagist]: https://packagist.org/packages/webwizo/laravel-shortcodes\n[link-travis]: https://travis-ci.org/webwizo/laravel-shortcodes\n[link-scrutinizer]: https://scrutinizer-ci.com/g/webwizo/laravel-shortcodes/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/webwizo/laravel-shortcodes\n[link-downloads]: https://packagist.org/packages/webwizo/laravel-shortcodes\n[link-author]: https://github.com/webwizo\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebwizo%2Flaravel-shortcodes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebwizo%2Flaravel-shortcodes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebwizo%2Flaravel-shortcodes/lists"}