underpin/shortcode-loader

Underpin 的短代码加载器

1.1.0 2021-11-24 21:42 UTC

This package is auto-updated.

Last update: 2024-08-25 03:42:12 UTC


README

一个辅助将短代码注册到WordPress网站的加载器。

安装

使用Composer

composer require underpin/shortcode-loader

手动安装

此插件使用内置的自动加载器,所以只要在 Underpin 之前引入,它应该能按预期工作。

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

设置

  1. 安装 Underpin。请参阅Underpin 文档
  2. 根据需要注册新的短代码菜单。

示例

一个非常基础的例子可能看起来是这样的。

// 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

或者,你可以扩展 Shortcode 类,并直接引用扩展的类,如下所示

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