首页 > 解决方案 > 你会如何做这个基本的wordpress插件?

问题描述

我开始开发它,我意识到它有点棘手。我需要转换简码

[helloworld] into <h1>"Hello World"</h1> 

并且能够改变

"Hello World" from admin

有人可以指出我正确的方式吗?

标签: phpajaxwordpress

解决方案


您需要创建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
 */

在此标头下方添加上面的代码,并将文件放在插件目录中的文件夹中。

有关更多详细信息,请参阅插件基础


推荐阅读