Stop Errors when Running Multiple Themes
Another quick WordPress tip for anyone running multiple themes in WordPress. If your site provides users the option of selecting from a number of different themes, you may have noticed errors like this in your PHP error log:
[28-May-2009 05:46:50] PHP Warning: main(): Failed opening ‘/…/press/wp-content/themes/requiem/searchform.php’ for inclusion (include_path=’/usr/lib/php:.:/usr/php4/lib/php:/usr/local/php4/lib/php’) in /…/press/wp-content/themes/default/sidebar.php on line 6
[28-May-2009 05:49:02] PHP Warning: main(/…/press/wp-content/themes/requiem/searchform.php): failed to open stream: No such file or directory in /…/press/wp-content/themes/default/sidebar.php on line 6
These errors happen when a user loads a page using a non-default theme that calls the searchform.php file via the following code:
<?php include (TEMPLATEPATH . ‘/searchform.php’); ?>
Since the template path is based on the default theme, this code will attempt to locate searchform.php in the default theme’s directory. Thus, non-default themes that contain this code will produce the PHP errors shown above.
Fortunately, eliminating this problem is as easy as replacing the “TEMPLATEPATH” with the actual path to the file in your theme. Something like this:
<?php include (‘/…/press/wp-content/themes/default/searchform.php’); ?>
..where the “…” (ellipses) represents something like, “home/public/domain” or similar, depending on your setup. This path must be the absolute path to work properly. Repeat this process as necessary for any other instances of “TEMPLATEPATH”.
That’s all there is to it — no more pesky PHP errors for missing template files! :)