开发者

Replacing user text in post contents when rendered

开发者 https://www.devze.com 2023-02-14 19:43 出处:网络
What is the MOST correct way according to WP ideology to replace user text in the post content? Example: I want to replace [b] User Text[/b] To <strong> User text</strong> when text rende

What is the MOST correct way according to WP ideology to replace user text in the post content?

Example: I want to replace [b] User Text[/b] To <strong> User text</strong> when text rendered in the browser

Do I need filter? Do I need Short code API? Or it is perfectly fine to use PHP text replacing functions?

开发者_高级运维A small code sample will be highly appreciated.


I would use the Shortcode API, then your code for the functions.php would look something like this:

<?php
function shortcode_b_replace($atts, $content = null) {
    return '<strong>'.$content.'</strong>';
}
add_shortcode("b", "shortcode_b_replace");
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消