WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I were to load a custom library into wordpress, what would be the best place to add it?

Since there are a bunch of global vars defined at the top of the library, I would not want that to be done thru a hook where I'm forced to use a wrapper function whereby my library globals will be treated as local to that function.

My library starts with

ob_start()         //  I'm not sure how this would effect WP. So I'm not too big on this.
session_start();   //  I do need this though. 

This should make any wordpress page to be able to use PHP sessions, right? ( I'm assuming wordpress no internal code that kills/rejects session usage. )

If I put my library into a page such as mylibrary.php, how do I make sure that it gets included into wordpress ( all pages, cats, template files across themes ) and it will remain included even if I were to switch themes or deploy wordpress updates?

share|improve this question
up vote 1 down vote accepted

You might want to look into creating a MU (Must Use) plugin, see Wordpress Codex. Within this file, you can include your library (using require) or you could just tweak your library file a bit and use it directly as the MU plugin. The session_start() and ob_start() functions worked for me with ever-so-brief testing, but your mileage may vary so test test test :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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