Making More Extensible Code with add_theme_support

This is a cool article from Igor Benic about making your code more extensible. For one-off work, extensibility doesn’t really matter. But if you have a commercial plugin, it’s really nearly required in the WordPress ecosystem. The idea that really struck me was the first: letting people override a plugin’s front-end style with add_theme_support. What a cool idea! I don’t know if I’ve just been missing out, or that there isn’t a lot of support for this idea in the wild, but this was totally novel to me.

How do you make that happen. Igor’s code is:

if( ! current_theme_supports( 'my-plugin-style' ) ) {
    wp_enqueue_style( 'my-plugin-css', plugins_url( 'assets/plugin.css', __FILE__ )  );

Simple enough, but would perfectly serve the purpose.

He also goes over the other obvious ways that you can make your code extensible: apply filters, adding actions, allowing for template overriding by themes. He also has an idea I’ve never seen before about adding a filter to your shortcode to make it much easier for people who extend and replace it. That’s also a pretty great idea!

Add a Comment

Your email address will not be published. Required fields are marked *