Recently the question (How to add add custom functions to a theme) was posed in В последнее время вопрос (Как добавить добавлять пользовательские функции теме) был поставленный в WordPress Support Forum WordPress форум поддержки . Personally I faced the same question when re-designing Лично я столкнулся с вопросом, когда же вновь проектирования this site этот сайт . The following is a discussion of the option with the pros and cons. Ниже приводится обсуждение варианта с за и против.

There are two solutions. Есть два решения.
The first is to create a plugin which goes with the theme. Первый заключается в создании плагина, который выходит с темой. However the theme, when invoking functions defined in the plugin should check first for the availability of the function. Однако тема, когда ссылки на функции, определенные в плагине следует проверить на первый наличия функции. It should also provide a fallback option if the plugin is not available or has not been activated. Он должен также предусматривать Запасной вариант, если плагин не доступны или не была активирована.

 if(function_exists('your_function_name')) {     // Invoke your function: your_function_name()... если (function_exists ( 'your_function_name')) (/ / Вызовите ваши функции: your_function_name ()... else {     // Execute fallback option } остальное (/ / Execute Запасной вариант) 

The advantages are: Некоторые преимущества:

  • The plugin can be independently managed. Плагин может быть самостоятельно управлять.
  • The plugin can be reused for other purposes. Плагин может быть повторно использованы в других целях.

The disadvantages are: Недостатками являются:

  • It requires another additional step for the theme user to remember. Она требует другого дополнительного шага по теме пользователя запомнить.
  • It slightly complicates development and testing. Он слегка усложняет разработку и тестирование.

The second solution to this problem would be to incorporate the functionaility in a php file (as usual) which resides in the theme directory. Второе решение этой проблемы было бы включить в functionaility php-файл (как обычно), который находится в теме директории. This file is included in header.php like: Этот файл включается в header.php вроде:
include (’your_php_file.php’); включать ( 'your_php_file.php');

Yes you may also require it for simplicity like: Да, вы, возможно, также требуют его для простоты так:
require (’your_php_file.php’); требуется ( 'your_php_file.php');

The advantage to this approach is simplicity of usage and deployment by end-users. Преимущество такого подхода заключается в простоте использования и развертывания к конечным пользователям. It also simplifies development. Она также упрощает развитие.

If the user later decides to switch to a different theme and yet wants to retain the functionality, he would have to re-purpose the custom code into a plugin. Если пользователь впоследствии решит перейти на разные темы и в то же время хочет сохранить функциональность, ему придется пересмотреть цели собственный код в плагине.

In essence the reusability of the custom functionality determines the ideal location of the custom code. В сущности от повторного использования пользовательских функций определяет идеальное расположение собственный код.