我正在为 wordpress 编写一个简单的插件,它可以更改页面或帖子上的单个单词以使其变为粗体。
例如:vlbs -> vlbs
它适用于普通的 Wordpress 页面和使用此代码的帖子:
defined('ABSPATH') or die('You can\'t enter this site');
class VLBS {
function __construct() {
}
function activate() {
flush_rewrite_rules();
}
function deactivate() {
flush_rewrite_rules();
}
function unstinstall() {
}
function new_content($content) {
return $content = str_replace('vlbs','<strong style="color:#00a500">vlbs</strong>', $content);
}
}
if(class_exists('VLBS')){
$VLBS = new VLBS();
}
add_filter('the_content', array($VLBS, 'new_content'));
//activation
register_activation_hook(__FILE__, array($VLBS, 'activate'));
//deactivation
register_deactivation_hook(__FILE__, array($VLBS, 'deactivate'));
但是,它不适用于使用 Yootheme Pro Pagebuilder 构建的页面。函数 new_content() 中所做的任何事情都是在内容加载后处理的。因此,我无法在它显示给用户之前对其进行操作。
所以问题是:如何在页面显示之前获取页面的内容?是否有相当于 Wordpress 的“the_content”?
非常感谢任何帮助!非常感谢您提前。
最好的问候法比安
Yootheme:1.22.5
Wordpress:5.2.4
PHP:7.3
浏览器:在 Chrome、Firefox、Edge、Internet Explorer 上测试