underpin/shortcode-loader

Shortcode loader for Underpin

1.1.0 2021-11-24 21:42 UTC

This package is auto-updated.

Last update: 2024-05-25 03:06:35 UTC


README

Loader That assists with registering shortcodes to a WordPress website.

Installation

Using Composer

composer require underpin/shortcode-loader

Manually

This plugin uses a built-in autoloader, so as long as it is required before Underpin, it should work as-expected.

require_once(__DIR__ . '/underpin-shortcodes/shortcodes.php');

Setup

  1. Install Underpin. See Underpin Docs
  2. Register new shortcodes menus as-needed.

Example

A very basic example could look something like this.

// Register shortcode
underpin()->shortcodes()->add( 'shortcode-key', [
	'shortcode'                  => 'custom-shortcode',              // Required. Shortcode name.
	'defaults'                   => [ 'foo' => 'bar' ],              // Default atts. See shortcode_atts
	'shortcode_actions_callback' => function ( $parsed_atts ) {      // Required. Shortcode action.
		return $parsed_atts['key']; // 'value'
	},

] );

// Shortcode output examples
do_shortcode( '[custom-shortcode foo="baz"]' ); // baz
do_shortcode( '[custom-shortcode]' ); // bar

Alternatively, you can extend Shortcode and reference the extended class directly, like so:

underpin()->shortcodes()->add('shortcode-key','Namespace\To\Class');