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?

1

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

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

|improve this answer|||||
  • thanks, yes it is quicklatex plugin, now i try your code – sound wave Sep 29 '19 at 20:57
  • 1
    wpautop just adds paragraph tags. wptexturize might alter other things, like quotes. – Knut Sparhell Sep 29 '19 at 22:11
  • 1
    Does remove_all_filters( 'the_content' ) work? Remember to remove the filter late, like in 'init' or even 'wp_loaded'. Just removing when functions.php are loaded will not work, as not all filters are added yet. – Knut Sparhell Sep 29 '19 at 22:38
  • 1
    1) You need to always end all statements with a ; even if I forgot it in my comment. 2) Not other files, but actions determine when something should happen: add_action( 'wp_loaded', function() { remove_all_filters( 'the_content' ); } ); – Knut Sparhell Sep 29 '19 at 22:52
  • 1
    Then remove just wpautop. – Knut Sparhell Sep 29 '19 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.