【问题标题】:Modifying $post->post_content in WordPress在 WordPress 中修改 $post->post_content
【发布时间】:2015-05-03 08:26:19
【问题描述】:

我使用的模板似乎在搜索页面中输出$post->post_content

我维护了一个使用非标准短代码格式的插件,我正在尝试找出 如何在 $post->post_content 显示之前对其进行过滤,因为目前我的短代码没有被覆盖(再次,不使用 Shortcode API)。

这让我很难过。任何帮助,我将不胜感激。

【问题讨论】:

    标签: wordpress filtering shortcode


    【解决方案1】:

    我认为你可以使用the_post 动作钩子,它允许在查询和设置后立即修改帖子对象:

    add_action('the_post', function($post, $query){
    
        // do whatever you want to $post, for example:
        $post->post_content = str_replace('{YOUR_SHORTCODE}', 'WHATEVER', $post->post_content);
    
    }, 10, 2);
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 2022-06-25
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 2020-07-14
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多