Recently the question (How to add add custom functions to a theme) was posed in Recentemente la questione (Come aggiungere aggiungere funzioni personalizzate a un tema) è stata posta in WordPress Support Forum WordPress forum di supporto . Personally I faced the same question when re-designing Personalmente ho riscontrato la stessa domanda quando ri-progettazione this site questo sito . The following is a discussion of the option with the pros and cons. Il seguente è una discussione l'opzione con il pro e il contro.

There are two solutions. Ci sono due soluzioni.
The first is to create a plugin which goes with the theme. Il primo è quello di creare un plugin che va con il tema. However the theme, when invoking functions defined in the plugin should check first for the availability of the function. Tuttavia il tema, quando invocando funzioni definite nel plug-dovrebbe verificare prima per la disponibilità della funzione. It should also provide a fallback option if the plugin is not available or has not been activated. Essa dovrebbe inoltre fornire un ripiego opzione se il plugin non è disponibile o non è stato attivato.

 if(function_exists('your_function_name')) {     // Invoke your function: your_function_name()... if (function_exists ( 'your_function_name')) (/ / Richiama il tuo funzione: your_function_name ()... else {     // Execute fallback option } else (/ / Esecuzione di ripiego opzione) 

The advantages are: I vantaggi sono:

  • The plugin can be independently managed. Il plugin può essere gestito indipendentemente.
  • The plugin can be reused for other purposes. Il plugin possono essere riutilizzati per altri scopi.

The disadvantages are: Gli svantaggi sono:

  • It requires another additional step for the theme user to remember. Essa richiede un altro ulteriore passo per il tema utente da ricordare.
  • It slightly complicates development and testing. Si complica leggermente lo sviluppo e la sperimentazione.

The second solution to this problem would be to incorporate the functionaility in a php file (as usual) which resides in the theme directory. La seconda soluzione a questo problema sarebbe quello di integrare la functionaility php in un file (come al solito) che risiede in tema di directory. This file is included in header.php like: Questo file è incluso in header.php come:
include (’your_php_file.php’); include ( 'your_php_file.php');

Yes you may also require it for simplicity like: Sì si possono anche richiedere che per semplicità come:
require (’your_php_file.php’); richiedono ( 'your_php_file.php');

The advantage to this approach is simplicity of usage and deployment by end-users. Il vantaggio di questo approccio è la semplicità di utilizzo e di implementazione da parte degli utenti finali. It also simplifies development. Ha inoltre semplifica lo sviluppo.

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. Se l'utente decide più tardi a passare a un tema diverso e ancora vuole mantenere la funzionalità, che avrebbe dovuto ri-fine, il codice personalizzato in un plugin.

In essence the reusability of the custom functionality determines the ideal location of the custom code. In sostanza la riutilizzabilità dei personalizzato funzionalità determina la posizione ideale del codice personalizzato.