• GusGF

    (@gusgf)


    WP explanation of what hook ‘after_setup_theme’ does has left me more confused:

    This hook is called during each page load, after the theme is initialised. It is generally used to perform basic setup, registration, and init actions for a theme.

    Okay so it’s called after the theme is initialised hence the name ‘after_setup_theme’.

    BUT THEN IT SAYS it performs basic setup, registration, and init actions for a theme.

    That’s telling me it’s involved in setting the theme up from the word go and not something that comes in after the theme has been setup??? How confusing.

    • This topic was modified 6 years ago by GusGF.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Joy

    (@joyously)

    You have to remember that there are two perspectives here. One is core WordPress code which is loading the theme (“theme is initialized”). The other is the theme code which is hooking to the after_setup_theme action “to perform basic setup, registration, and init actions for a theme”.

    The WP core doesn’t know how to do the specifics for a theme, so it loads the files and calls do_action('after_setup_theme') so that the theme can do all the specifics it needs when it first loads.

    Moderator bcworkz

    (@bcworkz)

    It’s not so much for basic setup, registration, and init actions that a specific theme does for itself, though that is a possibility. It’s more so other plugins that need to do basic setup, registration, and init actions that first require the theme be setup can do so at the right point in the loading process. Plugins load fairly early, too early to do anything that relies upon theme setup. This allows them to do stuff after the theme has been setup.

    To abstract this further, it’s an action that fires at a particular time. We can use it for any purpose we want that requires execution at this point. The purpose of any action is open ended. We can use it for anything beyond what it may have been intended for. I’ve even used filters as actions because they fired when I needed to do something even though what I needed to do was entirely unrelated to the filter’s purpose. All that really matters is a hook fires at the right time and you can access the data you need.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Confused about ‘after_setup_theme’’ is closed to new replies.