I just wasted nearly an hour troubleshooting a shortcode for a project because I did not know that WordPress shortcode attributes are passed through PHP’s
strtolower() function (view source).
I rarely use camelCase in PHP, and am also not a huge fan of shortcodes, so have easily managed to get through 15 years of developing WordPress sites without this issue ever popping up.
The use case of the shortcode I was building is to allow the user to display a HubSpot form inside of a WordPress post or page by providing a couple of required attributes, and optionally some additional attributes. The shortcode attributes directly correlate to the HubSpot form parameters. HubSpot forms use camel case for the parameter names, and I matched the shortcode attribute names to the HubSpot form parameter names without thinking much about it. I spent the next 45 minutes trying to figure out why the forms would only display using the default parameters and were ignoring the user provided parameters.
Of course, it turns out that the user parameters were being ignored because they no longer matched the expected attribute names after being converted to lowercase by the aforementioned
Don’t be like me. Use lowercase/snake_case attribute names in the