Skip to content

CommandCreateShortcode

rogertm edited this page Apr 8, 2026 · 1 revision

$ php cli/wasp create:shortcode

Descripción

Crea una clase de Shortcode y también su template en templates/shortcodes/.

Uso

create:shortcode [options] [--] <name> [<project>]

Argumentos

  • name Nombre del shortcode (ej: "Photo Gallery").
  • project Slug del proyecto destino (ej: wasp-child). Si se omite, usa wasp.

Opciones

  • --dry-run Simula la creación.
  • -h, --help Muestra la ayuda.

Ejemplos

php cli/wasp create:shortcode "Photo Gallery"
php cli/wasp create:shortcode "Photo Gallery" "wasp-child"
php cli/wasp create:shortcode "Photo Gallery" --dry-run

Resultado esperado

  • Crea clase en classes/shortcode/class-{project}-shortcode-photo-gallery.php.
    • Ejemplo en WASP: wasp/classes/shortcode/class-wasp-shortcode-photo-gallery.php
  • Crea template en templates/shortcodes/{project}_photo_gallery.php.
    • Ejemplo en WASP: wasp/templates/shortcodes/wasp_photo_gallery.php
  • Registra en inc/classes.php:
new {Namespace}\Shortcode\Shortcode_Photo_Gallery;

Fragmento de clase generada

class Shortcode_Photo_Gallery extends Shortcode
{
    public function __construct()
    {
        $this->shortcode_tag = 'wasp_photo_gallery';
    }
}

Override del template en el tema

Puedes sobreescribir el template generado creando:

wp-content/themes/your-theme/shortcodes/wasp_photo_gallery.php

Clone this wiki locally