【问题标题】:Wordpress: Create theme-unspecific shortcodes?Wordpress:创建主题不特定的简码?
【发布时间】:2013-12-10 22:31:00
【问题描述】:

我知道如何在特定 wordpress 主题的 functions.php 中创建自己的简码。有没有办法创建独立于使用的主题的全局短代码?

【问题讨论】:

  • 短代码功能不限于functions.php。你也可以加入插件。

标签: php wordpress wordpress-theming shortcode


【解决方案1】:
  1. 在 wp-content/plugins/my-custom-global-shortcode/ 中创建 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;
     }
     ?>
    

【讨论】:

    猜你喜欢
    • 2017-05-17
    • 2016-07-17
    • 1970-01-01
    • 2012-11-06
    • 2014-04-11
    • 2012-03-17
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多