1. Go to this page and download the library: Download maiorano84/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/ */
maiorano84 / shortcodes example snippets
use Maiorano\Shortcodes\Manager;
use Maiorano\Shortcodes\Library;
//Instantiate a Shortcode Manager
$manager = new Manager\ShortcodeManager;
//Create your shortcode
$example = new Library\SimpleShortcode('example', ['foo'=>'bar'], function($content=null, array $atts=[]){
return $content.$atts['foo'];
});
$manager->register($example)->doShortcode('[example]Foo[/example]'); //Outputs: Foobar
$manager = new ShortcodeManager([
'foo' => new Library\SimpleShortcode('foo', null, function ($content) {
return 'foo' . $content;
}),
'bar' => new Library\SimpleShortcode('bar', null, function () {
return 'bar';
})
]);
echo $manager->doShortcode('[foo][bar/][/foo]'); //Outputs: foo[bar/]
$manager = new ShortcodeManager([
'foo' => new Library\SimpleShortcode('foo', null, function ($content) {
return 'foo' . $this->manager->doShortcode($content, 'bar');
}),
'bar' => new Library\SimpleShortcode('bar', null, function ($content) {
return 'bar' . $content;
}),
'baz' => new Library\SimpleShortcode('baz', null, function () {
return 'baz';
})
]);