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
Name
Type
Default
Description
button_title
string
Add Shortcode
Text to display on the shortcode trigger button.
select_title
string
Select a shortcode
Placeholder to displayed when nothing is selected.
insert_title
string
Insert Shortcode
Text to display on the insert button
show_in_editor
bool
true
Flag to display media insert/upload buttons
defaults
array
Sets all default values from an external array (optional)
class
string
Extra CSS classes (space separated) to append to the main framework wrapper
Extra Shortcode Generator Framework Arguments
Name
Type
Description
view
string
View model of the shortcode (normal | contents | group | repeater)
shortcode_name
string
Set a unique slug-like name of shortcode
group_shortcode
string
Set a unique slug-like name of group shortcode.
group_fields
array
An 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',
),
)
));
}