Shortcode is a small piece of code, indicated by brackets like [this], that performs a dedicated function on your site. You can place it just about anywhere you’d like, and it will add a specific feature to your page, post, or other content. For example, you can use shortcodes to display galleries, videos, or even playlists.

Shortcodes

There are a number of default shortcodes available.

Name Parameters Description
[entries_fetch] id, field Fetch specific entry field.
[registry] name, default Fetch specific item from registry.
[url] Display application url.
You may ignore shortcodes processing by wrapping entry content in raw shortcode tag.

Shortocodes Details

[entries_fetch]

Fetch specific entry field.

Examples

[entries_fetch id="entry-id" field="field-name" default="default-value"]
[registry]

Fetch specific item from registry.

Examples

[registry_get name="item-name" default="default-value"]
[url]/documentation

Display application url.

Examples

[url]

Methods

Name Description
addHandler Add shortcode handler.
addEventHandler Add event handler.
process Processes text and replaces shortcodes.
parse Parses text into shortcodes.
getCacheID Get Cache ID for shortcode

Methods Details

addHandler

Add shortcode handler.

/**
 * Add shortcode handler.
 *
 * @param string   $name    Shortcode
 * @param callable $handler Handler
 *
 * @access public
 */
public function addHandler(string $name, callable $handler)

Examples

flextype('parsers')->shortcode()->addHandler('message', function () {
    return "Indeed. – Teal'c";
});
addEventHandler()

Add event handler.

/**
 * Add event handler.
 *
 * @param string   $name    Event
 * @param callable $handler Handler
 *
 * @access public
 */
public function addEventHandler(string $name, callable $handler)

Examples

flextype('parsers')->shortcode()->addHandler('raw', static function (ShortcodeInterface $s) {
    return $s->getContent();
});

flextype('parsers')
    ->shortcode()
    ->addEventHandler(Events::FILTER_SHORTCODES,
                      new FilterRawEventHandler(['raw']));

More details about events: github.com/thunderer/Shortcode#events

process

Processes text and replaces shortcodes.

/**
 * Processes text and replaces shortcodes.
 *
 * @param string $input A text containing SHORTCODE
 * @param bool   $cache Cache result data or no. Default is true
 *
 * @access public
 */
public function process(string $input, bool $cache = true)

Examples

$shortcode = 'text with [message]';

$html = flextype('parsers')->shortcode()->process($shortcode);
parse

Parses text into shortcodes.

/**
 * Parses text into shortcodes.
 *
 * @param string $input A text containing SHORTCODE
 *
 * @access public
 */
public function parse(string $input)

Examples

$shortcode = 'text with [message]';

$text = flextype('parsers')->shortcode()->parse($shortcode);
getCacheID

Get Cache ID for shortcode.

/**
 * Get Cache ID for shortcode
 *
 * @param  string $input Input
 *
 * @return string Cache ID
 *
 * @access public
 */
public function getCacheID(string $input): string

Examples

$shortcode = 'text with [message]';

$cache_id = flextype('parsers')->shortcode()->getCacheID($shortcode);

On This Page