Please read the WordPress docs for shortcodes.
We need to create a class for the shortcode.
<?php
namespace gotoAndPlay\Shortcodes;
use gotoAndCore\Plugins\Timber;
class Player {
public function __construct() {
add_shortcode('player', [$this, 'render']);
}
public function render($attr, $content = null) {
return Timber::compile('@player', $attr);
}
}
We also need to register the shortcode. We can do so in Theme.php
inside constructor method like shown below. If you’d like to add a TinyMCE button for that shortcode, read more here.
$this->shortcodes = [
'gtap_player' => new Player(),
];
Don’t forget to use the class.
use gotoAndPlay\Shortcodes\Player;