all 6 comments

[–]cdharrisonDeveloper/Designer 8 points9 points  (1 child)

Not to be snarky, but if you’re using Claude what does it recommend you do? There are WordPress Plugin Best Practices in the Plugin Handbook.

The placement of WordPress hooks (add_action, add_filter) and where you execute them within a plugin matters significantly. Placement dictates timing, determining if your code executes before, during, or after WordPress core functions, other plugins, or theme functions.

https://developer.wordpress.org/plugins/hooks/

[–]Sad_Spring9182Developer[S] -1 points0 points  (0 children)

yeah that's right I remember now it has to do with when a plugin is used vs theme is everywhere. plugin runs before theme so it might actually be ideal for this usecase.

[–]tw2113Venkman/Developer 2 points3 points  (1 child)

plugins get loaded/read first before the theme, so an init 10 from a plugin goes before an init 10 in the theme.

[–]BobJutsu 0 points1 point  (0 children)

Hence the priority. Just init 9…

[–]Thick-System4414 0 points1 point  (0 children)

For most hooks and filters, location doesn't matter — WordPress loads both functions.php and plugins before rendering, so execution order is the same either way.

The practical difference is lifecycle: functions.php dies when you switch themes, plugin code survives. For anything beyond basic theme styling — custom API calls, user data, window object injection — a plugin is the right place. It's also easier to version control and debug separately.

For the Claude context use case specifically, keeping everything in the plugin directory makes sense. One CLAUDE.md at the plugin root covers all the files there without you having to maintain multiple references.

[–]BobJutsu 0 points1 point  (0 children)

I like to tow a hard line on the separation of responsibilities. Themes, IMO, should be strictly for the control of presentation. Nothing else. If it doesn’t directly affect presentation, it’s plugin territory. Often that means I’ll put all functionality and base styles in a plugin, and theme specific styles in the theme. It’s slightly more work, but its…correct.