最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filters - How to use do_shortcode_tag to modify the output of a shortcode?

programmeradmin1浏览0评论

I would like to add shortcodes whose content gets processed by plugins before it gets displayed in the page.

In particular, I have a plugin which processes content between two $ signs to produce math formulas and graphs. A simple shortcode is

add_shortcode( 'test', 'test_sc' );
function test_sc( $atts ){ return "$\frac{15}{5} = 3$"; }

By writing $\frac{15}{5} = 3$ in a page this gets displayed

By writing [test] in a page this gets displayed $\frac{15}{5} = 3$

WordPress does a few things before the content from a page or post gets displayed on the site. For instance, it processes HTML paragraph (p) tags, it runs shortcodes and even sends the content to the theme and any plugins so they can do their thing to the content and include their bits.

I heard that using do_shortcode_tag (reference) it is possibile to do full content processing, but how to do that?

I would like to add shortcodes whose content gets processed by plugins before it gets displayed in the page.

In particular, I have a plugin which processes content between two $ signs to produce math formulas and graphs. A simple shortcode is

add_shortcode( 'test', 'test_sc' );
function test_sc( $atts ){ return "$\frac{15}{5} = 3$"; }

By writing $\frac{15}{5} = 3$ in a page this gets displayed

By writing [test] in a page this gets displayed $\frac{15}{5} = 3$

WordPress does a few things before the content from a page or post gets displayed on the site. For instance, it processes HTML paragraph (p) tags, it runs shortcodes and even sends the content to the theme and any plugins so they can do their thing to the content and include their bits.

I heard that using do_shortcode_tag (reference) it is possibile to do full content processing, but how to do that?

Share Improve this question asked Sep 29, 2019 at 20:09 sound wavesound wave 2151 gold badge3 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You have a LaTex plugin? It probably filters "the_content". Try

return apply_filters( 'the_content', '$\frac{15}{5} = 3$' );

发布评论

评论列表(0)

  1. 暂无评论