Ever since starting my first Wordpress blog in December 2005 I’ve come to appreciate what Wordpress brings to the table right out of the box.
From then to now I’ve started using Wordpress with websites where blogging is simply an added benefit; the main focus of the websites is something other than a blog.
As a one man show, Wordpress can be invaluable for creating websites that aren’t blog-centric.
You could always create your own repository of reusable website code and templates, but Wordpress gives you so much more: a broad user base that finds and quickly patches bugs, useful 3rd party plugins that you don’t have to develop yourself, and a plethora of themes that you can use to help get your website running (especially if you’re not a color guy like myself).
There is, however, one component you’ll need to build yourself when you want to use Wordpress for a website with dynamic content: a custom PHP library.
Integrating Your Own PHP Library into Wordpress
Integrating a custom PHP library into Wordpress can be done in three simple steps:
- Create a lib directory in the Wordpress root directory.
- Create a PHP script called LIB.php in the lib directory created in the first step.
- Modify wp-config.php and add the line include(”lib/LIB.php”); at the end of the file (before the ending ?> line).
The custom PHP library is now integrated into Wordpress, and you can now start building your custom PHP scripts and include them in the lib/LIB.php file.
Once you’ve built your library of functions you can add them into your Wordpress templates so that they show up on your site.
Other Reasons for Creating a Custom PHP Library
Other than managing dynamic data, you’ll also want to create a custom PHP library if you want to override any default Wordpress functions.
For example: one site I have overrides the get_the_title() and the_permalink() functions to do as I please.
Note that you’ll need to make sure you comment out the existing functions inside of the appropriate files located in the wp-includes directory.
Why Not Build a Plugin Instead?
Wordpress has a feature rich plugin interface, but if you’ve already got a custom PHP library then it’s much easier to integrate it into Wordpress using the methodology above.
Also, if you want to use your custom PHP library with more than just Wordpress (for performing background data parsing, for example) then using this method will give you the ability to perform this type of functionality with ease.
The only drawback to using this method is that you can’t easily attach menus to the Wordpress Site Admin interface as far as I can tell (although I’ve never tried), but I don’t have a need for this functionality, so it’s not a big deal for me (and hopefully not you, too).
Hopefully you find this guide useful when building your next Wordpress based website that’s more than just a plain old blog.
Tags: wordpress, php, custom, library