is there a way to hook / filter or add action that would be printed in the wp-config file? lets say i want to add some simple command like "empty the trash" aka

define('EMPTY_TRASH_DAYS', 1 ); 

This should be changes in the wp-config but i want it to go with theme..

Any way to do that?


There is, as far as I know, no way to hook into wp-config.php from a Theme. For one, wp-config.php shouldn't be writeable; for another, wp-config.php is executed well-before a Theme's functions.php file is parsed. For a great overview of how WordPress boots, have a look at this two-part post by Theme.FM (part 1, part 2) or this Explanation with a flowchart by @Rarst.

You might want to look into removing the define() from wp-config.php, and moving it into the Theme? I'll have to look to see where it gets used, but there's a good chance that WordPress won't have looked for it before functions.php gets parsed.


As per @ChristopherDavis' comment below, EMPTY_TRASH_DAYS gets defined at wp-settings.php, via default-constants.php. So, you have to define it in wp-config.php, if you want to override the default.

p.s. why would you want to define the number of trash days in a Theme, anyway?

| improve this answer | |
  • 1
    removing the define doesn't work. WordPress sets up defaults if they aren't defined in wp-config.php core.svn.wordpress.org/trunk/wp-includes/default-constants.php the functions in there get called in wp-settings.php – chrisguitarguy Oct 27 '11 at 20:12
  • @ChristopherDavis Well there ya go, then! Thanks for the clarification. (Note, I was referring to moving the define() to functions.php, not to removing it entirely.) – Chip Bennett Oct 27 '11 at 20:16
  • RE: the edit. Yes, exactly. It's not really a theme or plugins job to try and change wp-config options. – chrisguitarguy Oct 27 '11 at 20:20
  • ChristopherDavis, kaiser & chipbennett - Thanks a lot for the debate, your answers and the refrence links - it taught a lot :) - I really appreciate it – Sagive SEO Oct 28 '11 at 2:16
  • Just to expend on the reason i asked - i wanted to create a defaults / custom define attributed after new installation plugin that would offer a lot of easy to set common options. The "empty my trash" option was just a small example – Sagive SEO Oct 28 '11 at 2:21

You can just redefine it in your functions.php file (call define with the key/value you want). Since it loads later, it's going to be replaced with your value. I just tried this with a plugin, it generated some unexpected output errors, but it worked.

That said, if this is a theme for public consumption, it is definitely not your job to change site wide configuration options without consulting your users. If it's for a client, you should be able to edit their wp-config directly.

You're better off to use xref (or something like ack-grep) to search for where the constant is used and how. Are there hooks in those functions/whatever that you could used to accomplish the same thing as redefining the variable?

| improve this answer | |
  • 1
    Couldn't you use @define( etc... ) to avoid the error output? Not that it's a good idea, but it should work. – kaiser Oct 27 '11 at 20:51
  • Good call, I suppose you could. I only saw the "unexpected output" error during plugin activation. No other PHP warnings/errors (with WP_DEBUG set to true). – chrisguitarguy Oct 27 '11 at 21:15
  • Ah, unexpected output comes if you want to echo something during activation/deactivation/uninstallation. If you don't do that it's no problem. – kaiser Oct 27 '11 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.