Build custom WordPress shortcodes with visual builder
Lowercase letters, numbers, hyphens, underscores only
[tag]content[/tag]
[my_shortcode id="1"]Content goes here[/my_shortcode]Use this shortcode in your WordPress posts, pages, or widgets
<?php
/**
* Shortcode: [my_shortcode]
*/
function my_shortcode_shortcode($atts, $content = null) {
// Parse attributes
$atts = shortcode_atts(
array(
'id' => '1',
),
$atts,
'my_shortcode'
);
// Extract attributes
$id = $atts['id'];
// Process content
$content = do_shortcode($content);
// Build output
$output = '';
// TODO: Add your shortcode logic here
return $output;
}
// Register shortcode
add_shortcode('my_shortcode', 'my_shortcode_shortcode');
Add this code to your theme's functions.php or plugin file
1. Name Your Shortcode: Enter unique name (e.g., "pricing_table", "cta_button"). Use prefix to avoid conflicts with other plugins.
Self-Closing: Standalone shortcode [button]. Use for generating complete HTML output without user content.
Enclosing: Wraps content [highlight]text[/highlight]. Use when applying formatting or functionality to user-provided content.
2. Add Parameters: Define attribute names (color, size, id), data types (string, number, boolean), and default values.
3. Set Defaults: Always provide fallback values for missing attributes to prevent errors in edge cases.
4. Generate PHP Code: Tool creates complete add_shortcode() registration with handler function template.
5. Copy to Theme/Plugin: Paste into functions.php or plugin file. Customize output HTML in handler function.
Test shortcodes in posts/pages. Use do_shortcode() in templates. Always sanitize user input and escape output for security.
Shortcodes let users embed dynamic content in posts/pages without code. Common uses: galleries, forms, buttons, pricing tables, video embeds, custom queries. They make complex functionality accessible to non-technical users.
Self-closing shortcodes are standalone: [button]. Enclosing shortcodes wrap content: [highlight]text[/highlight]. Enclosing shortcodes let you apply formatting/functionality to user-provided content, while self-closing ones generate complete output.
Attributes pass parameters to shortcodes: [button color="red" size="large"]. Always provide defaults in your handler function for missing attributes. This tool generates properly formatted attribute syntax for both simple values and complex parameters.
Use descriptive, unique names to avoid conflicts with other plugins. Prefix with your plugin/theme slug: [myplugin_gallery]. Use lowercase and hyphens, avoid underscores (though they work). Keep names short but clear.