Integrating a Custom PHP Library into Wordpress

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:

  1. Create a lib directory in the Wordpress root directory.
  2. Create a PHP script called LIB.php in the lib directory created in the first step.
  3. 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: , , ,

If you enjoyed this post, get free updates by email or RSS.

Checkout These Related Posts

  • Building SAJAX Applications with Wordpress
  • Optimizing Kontera ContentLink Ads in Wordpress
  • Did You Remember to Update Your Wordpress Time Zone Offset for DST?
  • Fixing JavaScript Affiliate Links in Wordpress 2.1.1
  • How To Work Around the Transparent PNG Issue with IE
  • 3 Comments so far »

    1. Wild Bluff Matt said

      on February 26 2007 @ 1:26 pm

      I just started using WordPress the other week and have been very impressed with, as you said, out of the box functionality. I’m looking to pick up some books on PHP coding, but in the meantime, using all the available user generated plugins are great.

    2. Ryan J. Parker said

      on February 26 2007 @ 4:01 pm

      There are a lot of good plugins out there. I’m using the Feedburner Feed Replacement, Google Sitemaps, Head META Description, MyAvatars, and many more on this blog.

    3. Comment RSS · TrackBack URI

    Leave a comment

    Name: (Required)

    eMail: (Required)

    Website:

    Comment:

    Pingbacks/Trackbacks

    1. Pingback on February 27 2007 @ 6:51 am