Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active January 22, 2024 21:39
Show Gist options
  • Save vielhuber/00d0e64134ea74cc1d7d9a811ed0009f to your computer and use it in GitHub Desktop.
Save vielhuber/00d0e64134ea74cc1d7d9a811ed0009f to your computer and use it in GitHub Desktop.
shortcodes #wordpress
// [foobar]
add_shortcode('foobar', function() {
return 'foo and bar';
});
// [barbaz foo="bar"]
add_shortcode('barbaz', function($atts) {
$parsed = shortcode_atts([
'foo' => 'default1',
'bar' => 'default2',
], $atts);
return 'foo: '.$parsed['foo'].' - bar: '.$parsed['bar'];
});
// run
echo do_shortcode('[barbaz foo="bar"]');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment