How to add custom functions to a WordPress 1.5 theme? Cómo agregar funciones personalizadas a un tema de WordPress 1,5?
Recently the question (How to add add custom functions to a theme) was posed in Recientemente la cuestión (¿Cómo añadir funciones personalizadas con un tema) se plantean en WordPress Support Forum Foro de soporte de WordPress . Personally I faced the same question when re-designing Personalmente me enfrenté la misma pregunta cuando volver a diseñar this site este sitio . The following is a discussion of the option with the pros and cons. La siguiente es una discusión de la opción con los pros y los contras.
There are two solutions. Hay dos soluciones.
The first is to create a plugin which goes with the theme. La primera es la creación de un plugin que va con el tema. However the theme, when invoking functions defined in the plugin should check first for the availability of the function. Sin embargo el tema, al invocar funciones definidas en el complemento debe comprobar primero para la disponibilidad de la función. It should also provide a fallback option if the plugin is not available or has not been activated. También debería proporcionar una opción de repliegue, si el plugin no está disponible o no se ha activado.
if(function_exists('your_function_name')) { // Invoke your function: your_function_name()... if (function_exists ( 'your_function_name')) (/ / Invoke su función: your_function_name ()... else { // Execute fallback option } else (/ / Ejecutar opción de repliegue)
The advantages are: Las ventajas son:
- The plugin can be independently managed. El complemento se puede independiente administrado.
- The plugin can be reused for other purposes. El plugin se puede reutilizar para otros fines.
The disadvantages are: Las desventajas son las siguientes:
- It requires another additional step for the theme user to remember. Se requiere otro paso adicional para el tema de usuarios de recordar.
- It slightly complicates development and testing. Se complica un poco el desarrollo y pruebas.
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 segunda solución a este problema sería la de incorporar la functionaility php en un archivo (como de costumbre) que reside en el directorio tema. This file is included in header.php like: Este archivo se incluye en header.php como:
include (’your_php_file.php’); include ( "your_php_file.php ');
Yes you may also require it for simplicity like: Sí es posible que también lo necesitan para la simplicidad como por ejemplo:
require (’your_php_file.php’); requieren ( 'your_php_file.php');
The advantage to this approach is simplicity of usage and deployment by end-users. La ventaja de este enfoque es la sencillez de uso y el despliegue de los usuarios finales. It also simplifies development. También simplifica el desarrollo.
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. Si el usuario decide más tarde pasar a un tema diferente y, sin embargo, quiere mantener la funcionalidad, tendría que volver a propósito el código personalizado en un plugin.
In essence the reusability of the custom functionality determines the ideal location of the custom code. En esencia la reutilización de la funcionalidad de la costumbre determina la ubicación ideal del código personalizado.
Filed under Filed under CMS Software CMS Software , Headline News Headline News , How To Cómo , Pro Blogging Blogging Pro , Technology Tecnología , Web , WordPress | |
| |
RSS 2.0 RSS 2,0 | |
Email this Article Enviar artículo
You may also like to read También puede leer |




June 3rd, 2005 at 2:48 pm 3 de junio de 2005, a las 2:48 pm
Thanks for this. Gracias por ello. ~I am new to both WordPress and PHP but also wanted a few home cooked functions. ~ Soy nuevo a ambos WordPress y PHP, pero también quería unos casera funciones. In my case I wanted to change a couple of WP functions to return differently so I copied these, renamed them and made my changes so as not to disturb distributable files. En mi caso yo quería cambiar un par de WP funciones para volver diferente por lo que copiar estos, rebautizado como ellos e hizo los cambios para no molestar a los archivos distribuibles. Not knowing where to put them, I just created a my-hacks.php file and turned that one. No saber dónde ponerlas, me acaba de crear una mi-hacks.php archivo y resultó que uno. All works fine. Todo funciona bien. But is this NOT a good place to put my code? Pero esto no es un buen lugar para poner mi código?
Appreciate any advice. Agradecemos cualquier consejo. Thanks Gracias
June 3rd, 2005 at 7:54 pm 3 de junio de 2005, a las 7:54 pm
As I mentioned above, I think you should just create a plugin and put them there. Como he mencionado anteriormente, creo que eso deberá crear un plugin y poner en él.
Ideally in your template you can check if the function is available (or whether the plugin is active) and then use it, if not use the default WordPress function. Lo ideal sería que en su plantilla puede comprobar si la función está disponible (o si el plugin está activa) y luego lo utilizan, si no uso la función por defecto de WordPress.
I too use several such customized functions on my site all packed away in a generic plugin named Impact (named after my custom theme). Yo también uso varias de esas funciones personalizadas en mi sitio todos los envasados de distancia en un plugin llamado genérico de impacto (el nombre de mi tema personalizado).
June 4th, 2005 at 5:45 pm 4 de Junio, 2005 a las 5:45 pm
Thanks for the advice. Gracias por el consejo. I’ll collect them all together if a my-hacks file until I;m complete then set about converting to a custom plugin as you suggest,Thanks again Voy a recoger todos juntos si uno de mis hacks archivo hasta que yo, m completo entonces se dedicó a convertir a una costumbre plugin como usted sugiere, Gracias de nuevo