How to add theme support?

It really just depends on what you need to do here. The general method is to hook all your theme support features to after_setup_theme for some obvious reasons.

after_setup_theme is the first action hook available to themes to add any type of support the theme. Certain features has to be registered here and cannot be registered later. One feature that jumps to mind is support for post formats. post_format is a build-in taxonomy which is registered on init. If we skip the following actions:

  • auth_cookie_malformed

  • auth_cookie_valid

  • set_current_user

init will be the next hook after after_setup_theme to do plugin and theme related stuff on. As post_format are registered on init, adding theme support here will be too late with the wrong priority. So if you need to check for theme support for post formats, you need to do that on after_setup_theme with a very low priority. I tend to use the PHP_INT_MAX constant value as priority or PHP_INT_MAX + 1 . You can also maybe try set_current_user which runs after after_setup_theme and just before init

Generally, all build-in theme support features are executed on after_theme_support to keep consistancy in your code, but you should not rely on that at all. As @toscho described in his answer here, wp_loaded is an excellent hook to use to check if a certain feature is already supported or not (there are exceptions, see below note). By the time wp_loaded fires, all theme support features should have been added, if not, then that theme is doing something very wrong and you really cannot compromise your code to adjust for a bad theme. All hooks after wp_loaded are concerned with content output and manipulating the ouput which will be send to browser.

IMPORTANT NOTE

As I already stated, some features like post format support cannot be added on init or any hook after that as it is too late, so wp_loaded in this case would be way too late to add theme support for post formats. As I already stated you would need to hook your function as late as possible to after_setup_theme

CONCLUSION

There is now real correct hook to use here. The hook would depend on the support feature. In general it would be safe to use wp_loaded to check for a specific custom support feature and in my opinion this would be the latest hook which you should use to add any type of theme support feature. For the build-in support features, after_setup_theme with a very low priority (or even set_current_user) should suffice as init is too late to add features like post formats

error code: 523