Last active
January 22, 2024 21:39
-
-
Save vielhuber/00d0e64134ea74cc1d7d9a811ed0009f to your computer and use it in GitHub Desktop.
shortcodes #wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [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