Shortcodes
WordPress Shortcodes can be added to the Main Class with Ayuco or manually.
Ayuco Command
php ayuco add shortcode:{shortcode} {handler}
{shortcode} | The shorcodes's string key (i.e. hello_world). This will be used to identify the shortcode in the content (i.e. [hello_world] ). |
{handler} | A controller or view to handle the shortcode. |
Example:
php ayuco add shortcode:hello_world view@shortcodes.hello-world
In the command above, Ayuco will add Wordpress shortcode “[hello-world]” to the project and will establish view “shortcodes.hello-world” as the handler.
Ayuco Is Awesome
If no handler is defined, Ayuco will default it to “AppController“. If the defined controller in the command doesn’t exist then Ayuco will create it. If the defined controller’s method in the command doesn’t exist then Ayuco will create it. If the defined view in the command doesn’t exist then Ayuco will create it.Add Manually
Shortcodes can be added manually by defining them in the Main Class.
class Main extends Bridge { public function init() { // Shortcode "[hello_word]" added. View as handler. $this->add_shortcode('hello_world', 'view@shortcodes.hello-world'); // Shortcode "[my_sc]" added. Controller as handler. $this->add_shortcode('my_sc', 'ShortcodeController@sc'); } }
In the sample above, multiple shortcodes have been added to the Main Class. Notice how handlers are defined.