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?
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
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.
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.
精彩评论