繁体   English   中英

如何在WordPress中替换短代码?

[英]How can I replace shortcode in WordPress?

我是WordPress的新手。 我正在尝试创建一个插件。 我正在使用静态短代码:

[SRPMGT id=12345]

这个短代码可以放在任何页面中。 我想用html内容替换这个短代码:

<div class="result"> Content to replace... </div>

注意:此短代码可以放在任何页面中。

请帮我解决这个问题。 提前致谢。

function add_shortcode($ tag,$ func)

是你需要知道的核心。

所以插入你的functions.php:

function srpmgt_shortcode(){return'Content to replace ...'; }

add_shortcode('SRPMGT_id = 12345','srpmgt_shortcode');

将以下代码添加到插件的functions.php文件中

// [srpgmt id="id-value"]
function srpgmt_func( $atts ) {
    extract( shortcode_atts( array(
        'id' => 'something',        
    ), $atts ) );

    return '<div class="result"> Content to replace... </div>';
}
add_shortcode( 'srpgmt', 'srpgmt_func' );

正如评论中已经提到的,进一步阅读请访问: http//codex.wordpress.org/Shortcode_API

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM