Shortcode Generator
Typed attributes, shortcode_atts() defaults and the right escaping function for every value — without you having to remember which is which.
The shortcode
[]
Lowercase, underscores rather than dashes, and prefixed so no other plugin claims it first.
Attributes
The type decides the sanitiser and the escaping.
sanitize_text_field() → esc_html()
absint()
in_array() against the choices → esc_attr()
Output markup
Write HTML. Drop an attribute in with {name}.
Insert:
Behaviour
Enclosing shortcode
Accepts wrapped content as {content}
Run in classic text widgets
Run in excerpts
// Generated with WP CodeKit — powered by GrowQuest (https://growquest.io). /** * [team_grid] shortcode. * * @param array $atts { * Shortcode attributes. * * @type string $title Heading shown above the grid. Default 'Our team'. * @type int $columns How many columns to render. Default '3'. * @type string $layout Grid or single-column list. Default 'grid'. * } * @return string Rendered HTML. */ function mytheme_team_grid_shortcode( $atts ) { $atts = shortcode_atts( array( 'title' => 'Our team', 'columns' => '3', 'layout' => 'grid', ), $atts, 'team_grid' ); $title = sanitize_text_field( $atts['title'] ); $columns = absint( $atts['columns'] ); $layout = in_array( $atts['layout'], array( 'grid', 'list' ), true ) ? $atts['layout'] : 'grid'; return sprintf( '<section class="team-grid team-grid--%s" style="--columns: %s">' . "\n" . ' <h2 class="team-grid__title">%s</h2>' . "\n" . '</section>', esc_attr( $layout ), $columns, esc_html( $title ) ); } add_shortcode( 'team_grid', 'mytheme_team_grid_shortcode' );