The Benefit of Using PHP Include Function in Optimizing Your WordPress Blog Theme

I’m always a fan of PHP’s Include function, especially in tweaing WordPress theme.

<?php include (‘file-to-include.php’); ?>

Aside from core WordPress theme functions and common use of Include in PHP-based programming, I found some use of it in term of safe-tweaking your WordPress blog theme’s codes.

Here’s an example. Suppose you want to have your Google AdSense code embedded into the top of your WordPress blog’s index.php. Sure, you can add the code right away into index.php – However, I enjoy using Include function to embed the AdSense code. No WordPress plugin necessary…

Here’s how:

  • I create, for example, adsense-code-top.php file containing your Google AdSense code.
  • I then include the file into index.php by putting <?php include (‘adsense-code-top.php’); ?> in the place I desire, for example, below the header.

Here are some benefits of using your custom Include function in your WordPress blog.

  • If you happen to crash your WordPress blog due to coding errors, you can easily check what and where the errors are by looking into your custom PHP files, instead of your WordPress theme files.
  • You can edit your codes faster by looking at the right custom PHP files you create, instead of scanning hundreds lines of WordPress codes.
  • You increase your WordPress blog’s coding usability – If you have someone tweak your blog’s theme codes, you can make her life easier by having your add-on organized in custom files (of course, don’t use obscure file name for your custom files – e.g. adsense-code.php is way much better than custom169236.php.

If you have other tips, please share by commenting on this post 🙂

Jun 4, 2009 by
GreenGeeks WP Web Host ad ad ad ad