Wordpress:创建主题不特定的短代码


Wordpress: Create theme-unspecific shortcodes?

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

  1. 在wp-content/plugins/my自定义全局短代码中创建my-custom-global-shortcode.php/
  2. 将此代码粘贴到该文件中,您就拥有了一个有效的全局快捷代码
  3. 修改shortcode_handler函数以执行您的竞标

     /*
     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;
     }
     ?>