duanlun2827 2015-10-10 16:19
浏览 33
已采纳

如何使用一行PHP部署一大块代码?

Recently in a huge flurry of Wordpress related googling I came across a possible solution to my problem of that time which used a method I hadn't come across before: Part of the process was including in the functions.php file the code which would have otherwise been placed in the template files of the site. That code was then "injected" into the theme files with one simple line of code. Something like:

<?php insert_custom_code(); ?>

I loved how clean this kept the template files, by allowing me to write the code related to some trickery and tucking it away in functions. Now I've also learned about creating site specific plugins so I can wrap that sort of stuff up in even tidier packages. Unfortunately that specific solution didn't work for my problem at that time, and I've lost that information.

I think this is a straight forward and standard part of Wordpress work - especially related to plugin and theme development, but I'm not sure what it's called or how to find it. So my question is: Does anyone know what this is called? Or where it might live in the wordpress codex or any other documentation that might help? I really appreciate it.

  • 写回答

1条回答 默认 最新

  • dongshuogai2343 2015-10-10 16:35
    关注

    It is simple PHP language style of declaring and calling a function! We are essentially calling a function which was defined/declared in functions.php or any included file.

    In PHP we can call any function with its name and (); e.g. for a function named myFunction, we can call it as myFunction();

    http://www.w3schools.com/php/php_functions.asp

    This is same as we call other built-in WordPress functions like, get_the_title(); or the_title(); etc

    And to declare your own custom functions in functions.php

    You may use this syntax:

    function your_function_name(){
         //your php code here
    
    }
    

    Then as functions.php is included by WordPress in all theme files, you can then simply call this function in any theme php file as:

    your_function_name();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答