tags:

views:

102

answers:

4

Often times, when I try to add my own custom PHP source codes to the template files (sidebar.php, index.php, header.php, etc...), it generates errors. However, it works properly on it's own outside of Wordpress. Is there a way for me to use my custom PHP stuff in Wordpress' template files?

+2  A: 

If you're talking about the sidebar.php, index.php and header.php in wp-content/themes/themename/, well, of course you can edit these files. They are meant to be edited. Only make sure that you don't overwrite existing PHP functions...

You can read about that on Wordpress' Docs

Harmen
A: 

In order to execute your own PHP files, you need to install exec-php plug-in.

http://wordpress.org/extend/plugins/exec-php/installation/

You can use your own PHP source codes on posts, pages and text widgets. Additionaly, if you want to use these codes on your template, there should not be any problems with this...

woofeR
No - you only need a plugin if you want to put php *inside* posts/pages. To edit templates, you won't need a plugin.
adam
A: 

With Wordpress you can extend Wordpress functionality by writing your own plugins. This is a fairly pain free process.

http://codex.wordpress.org/Writing_a_Plugin

You can also extend the functionality that templates have by putting functions into the functions.php template file.

http://codex.wordpress.org/Theme_Development#Theme_Functions_File

Adding custom php code to templates shouldn't generate errors. The only problem you might be having is that your code is conflicting with existing wordpress function names and variables.

JasonS
+1  A: 

No plugin required to add your own php, but to maintain upgradability you should, as far as possible, avoid altering core WP files and place your code within your own theme's files or in your own plugins. If you're getting errors it's hard to guess at what they may be without details, but I've found that, apart from simple parse errors etc., the most likely causes are scoping errors.

TimS