Im making a custom shortcode for my wordpress site and im just running through the example from the shortcode api for wordpress:
function myshortcode() {
$atts = shortcode_atts(
array(
'custom_title' => 'Your Title',
'custom_message' => 'Your Message',
), $atts);
return 'Test: ' . $atts['custom_title'] . ' ' . $atts['custom_message'];
}
add_shortcode('my-short','myshortcode');
The shortcode in my blog post is:
[my-short custom_title="Test" custom_message="123 Roman Ridge"]
but it outputs
Test: Your Title Your Message
there is nothing else in my blog post except the shortcode, any suggestions?
1 Answer
Note the following line in your function defintion:
function myshortcode() {
it’s missing the input parameters $atts
and $content
so that’s why you only get the default attribute values.
Replace it with:
function myshortcode( $atts = [], $content="" ) {