Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 创建主题不特定的短代码?_Php_Wordpress_Wordpress Theming_Shortcode - Fatal编程技术网

Php 创建主题不特定的短代码?

Php 创建主题不特定的短代码?,php,wordpress,wordpress-theming,shortcode,Php,Wordpress,Wordpress Theming,Shortcode,我知道如何在特定wordpress主题的functions.php中创建自己的短代码。有没有一种方法可以创建全局短代码,它独立于使用的主题工作 在wp-content/plugins/my-custom-global-shortcode内创建my-custom-global-shortcode.php/ 将此代码粘贴到该文件中,您就拥有了一个运行正常的全局快捷码 修改shortcode_handler函数以执行您的出价 /* 插件名称:短代码插件 插件URI: 描述:我的全局短代码 版本:1.

我知道如何在特定wordpress主题的functions.php中创建自己的短代码。有没有一种方法可以创建全局短代码,它独立于使用的主题工作

  • 在wp-content/plugins/my-custom-global-shortcode内创建my-custom-global-shortcode.php/
  • 将此代码粘贴到该文件中,您就拥有了一个运行正常的全局快捷码
  • 修改shortcode_handler函数以执行您的出价

    /*
    插件名称:短代码插件
    插件URI:
    描述:我的全局短代码
    版本:1.0
    作者:
    作者URI:
    */
    //注册[我的自定义全局快捷码]
    添加快捷代码(“我的自定义全局快捷代码”、“快捷代码处理程序”);
    //使用短代码调用的函数
    函数shortcode_handler(){
    $html='helloworld!';
    返回$html;
    }
    ?>
    

  • shortcode函数不限于functions.php。你也可以插入一个插件。
     /*
     Plugin Name: Shortcode Plugin
     Plugin URI: 
     Description: My Global Shortcode
     Version: 1.0
     Author: 
     Author URI: 
     */
    
     //register [my-custom-global-shortcode]
     add_shortcode("my-custom-global-shortcode", "shortcode_handler");
    
     // the function called with the shortcode
     function shortcode_handler() {
       $html = '<div>Hello World!</div>';
       return $html;
     }
     ?>