Slide 18
Slide 18 text
18
Register a shortcode
A. Go to the file includes/class-plugin-name-loader.php and add the following code:
protected $shortcodes;
Public function __construct () {
// …
$this->shortcodes = array();
}
public function add_shortcode( $tag, $component, $callback, $priority = 10, $accepted_args = 2 ) {
$this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback, $priority, $accepted_args );
}
public function run() {
//…
foreach ( $this->shortcodes as $hook ) {
add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'],
$hook['accepted_args'] );
}
}
Source: https://github.com/JoeSz/WordPress-Plugin-Boilerplate-Tutorial/blob/master/plugin-name/tutorials/register_a_shortcode_in_plugin.php