php - 你会如何做这个基本的wordpress插件?
问题描述
我开始开发它,我意识到它有点棘手。我需要转换简码
[helloworld] into <h1>"Hello World"</h1>
并且能够改变
"Hello World" from admin
有人可以指出我正确的方式吗?
解决方案
您需要创建hellowrold
为简码。
function hellowrold_func( $atts ) {
$a = shortcode_atts( array(
'content' => 'Default content',
), $atts );
return "<h1>{$a['content']}</h1>";
}
add_shortcode( 'hellowrold', 'hellowrold_func' );
然后,您可以像这样使用它,并根据需要从 content 属性更改文本。
[hellowrold content="Hello World"]
有关更多详细信息,请参阅简码 API。
如果您需要将其添加到插件中,只需创建一个带有如下标题内容的文件:
/**
* Plugin Name: YOUR PLUGIN NAME
*/
在此标头下方添加上面的代码,并将文件放在插件目录中的文件夹中。
有关更多详细信息,请参阅插件基础。
推荐阅读
- ios - 是否可以让以下网页在 Xcode 的 wkwebview 中工作?什么是配置?
- python-3.x - 为什么 __qualname__ 在 @classmethod 中的工作方式与在元类中不同
- r - 有效地从列表中创建配对的人,条件是他们以前从未配对过
- kubernetes - EKS 上的 AWS ALB 入口性能糟糕
- javascript - Javascript通过互值减少对象数组
- python - 展开 Pandas Dataframes 按不同范围添加行
- c++ - 从 CGAL 中的 General_polygon_set_2 解析单个曲线
- c++ - 字节流中的字符串搜索
- c++ - C ++中全局“运算符删除”的两种变体是什么?
- javascript - 有没有办法可以在其他文件的对象中声明函数?