1. Home
  2. Docs
  3. WordPress Studio Framework
  4. Framework Locations
  5. Shortcode Generator

Shortcode Generator

The WordPress Studio Framework (WPSF) can also be used to create custom WordPress shortcodes that can be used in both the Classic Editor as well as the new Block Editor.

Shortcode Generator Framework Arguments

NameTypeDefaultDescription
button_titlestringAdd ShortcodeText to display on the shortcode trigger button.
select_titlestringSelect a shortcodePlaceholder to displayed when nothing is selected.
insert_titlestringInsert ShortcodeText to display on the insert button
show_in_editorbooltrueFlag to display media insert/upload buttons
defaultsarray Sets all default values from an external array (optional)
classstring Extra CSS classes (space separated) to append to the main framework wrapper

Extra Shortcode Generator Framework Arguments

NameTypeDescription
viewstringView model of the shortcode (normal | contents | group | repeater)
shortcode_namestringSet a unique slug-like name of shortcode
group_shortcodestringSet a unique slug-like name of group shortcode.
group_fieldsarrayAn associative array containing fields for the fieldsets.

Shortcode Generator Framework Example

// Check to see if the WPSF class is already loaded
if ( class_exists( 'WPSF' ) ){
  
  //Set unique ID
  $prefix = 'custom_shortcode';

  //Create a Shortcode
  WPSF::createShortcoder( $prefix, array(
    'button_title' => 'Custom Shortcode',
  ));

  // Basic Shortcode Section
  WPSF::createSection( $prefix, array(
    'title' => 'Basic Shortcode Example',
    'view' => 'normal', //View model of the shortcode (normal | contents | group | repeater)
    'shortcode' => 'custom_shortcode', //unique slug name
    'fields' => array(
      array(
        'id' => 'title'
        'type' => 'text',
        'title' => 'Example Title',
      ),
      array(
        'id' => 'color',
        'type' => 'color',
        'title' => 'Color Title',
      ),
    )
  ));
}

Shortcode Generator Framework Example with Contents

// Check to see if the WPSF class is already loaded
if ( class_exists( 'WPSF' ) ){
  
  //Set unique ID
  $prefix = 'custom_shortcode';

  //Create a Shortcode
  WPSF::createShortcoder( $prefix, array(
    'button_title' => 'Custom Shortcode',
  ));

  // Basic Shortcode Section
  WPSF::createSection( $prefix, array(
    'title' => 'Content Shortcode Example',
    'view' => 'contents',
    'shortcode' => 'custom_shortcode', //unique slug name
    'fields' => array(
      array(
        'id' => 'content_1'
        'type' => 'textarea',
        'title' => 'Content
      ),
      array(
        'id' => 'content_2',
        'type' => 'textarea',
        'title' => 'Content 2',
      ),
    )
  ));
}

Shortcode Generator Framework Example with Groups

// Check to see if the WPSF class is already loaded
if ( class_exists( 'WPSF' ) ){
  
  //Set unique ID
  $prefix = 'custom_shortcode';

  //Create a Shortcode
  WPSF::createShortcoder( $prefix, array(
    'button_title' => 'Custom Shortcode',
  ));

  // Basic Shortcode Section
  WPSF::createSection( $prefix, array(
    'title' => 'Group Shortcode Example',
    'view' => 'groups',
    'shortcode' => 'custom_shortcode', //unique slug name
    'fields' => array(
      array(
        'id' => 'content_1'
        'type' => 'textarea',
        'title' => 'Content
      ),
      array(
        'id' => 'content_2',
        'type' => 'textarea',
        'title' => 'Content 2',
      ),
    ),
    'group_shortcode' => 'tab',
    'group_fields' => array(
      array(
        'id' => 'title',
        'type' => 'text',
        'title' => 'Example Title',
      ),
      array(
        'id' => 'content',
        'type' => 'textarea',
        'title' => 'Content',
      )
    ),
  ));

  //Another basic group shortcode
  WPSF::createSection( $prefix, array(
    'title' => 'Shortcode Example Two',
    'view' => 'group',
    'shortcode' => 'accordions',
    'group_shortcode' => 'accordion',
    'group_fields' => array(
      array(
        'id' => 'title',
        'type' => 'text',
        'title' => 'Title',
      ),
      array(
        'id' => 'content',
        'type' => 'textarea',
        'title' => 'Content',
      ),
    )
  ));
}

Shortcode Generator Framework Example with Repeater

// Check to see if the WPSF class is already loaded
if ( class_exists( 'WPSF' ) ){
  
  //Set unique ID
  $prefix = 'custom_shortcode';

  //Create a Shortcode
  WPSF::createShortcoder( $prefix, array(
    'button_title' => 'Custom Shortcode',
  ));

  // Basic Shortcode Section
  WPSF::createSection( $prefix, array(
    'title' => 'Repeater Shortcode Example',
    'view' => 'repeater',
    'shortcode' => 'custom_shortcode', //unique slug name
    'fields' => array(
      array(
        'id' => 'content'
        'type' => 'textarea',
        'title' => 'Content
      ),
      array(
        'id' => 'content',
        'type' => 'textarea',
        'title' => 'Content',
      ),
    ),
  ));
}
Was this article helpful to you? Yes No

How can we help?