PHP code example of vedmant / laravel-shortcodes

1. Go to this page and download the library: Download vedmant/laravel-shortcodes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vedmant / laravel-shortcodes example snippets


[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]

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

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

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

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

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

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

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

class YourShortcode extends Shortcode
{
    /**
     * Render shortcode
     *
     * @param string $content
     * @return string
     */
    public function render($content)
    {
        $atts = $this->validate([
            'post_id' => '

$data = Shortcodes::registeredData();
bash
php artisan vendor:publish --tag=shortcodes
bash
php artisan make:shortcode PostsListShortcode