0

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
  • 1
    Custom PHP should run fine whether in Wordpress or not, as long as nothing collides with Wordpress's set of functions. Please quote the error messages your get, and parts of your code. Commented Jan 15, 2010 at 10:29
  • A bit more description of what you're trying to actually accomplish would be more helpful for us I think. Commented Jan 15, 2010 at 10:47

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.