Wordpress using echo vs return in shortcode function

后端 未结 6 2172
我在风中等你
我在风中等你 2021-01-01 22:07

I just noticed, both echo and return works fine for displaying content from a shortcode function in wordpress.

function foobar_short         


        
6条回答
  •  死守一世寂寞
    2021-01-01 22:31

    Echo may work in your specific case but you definitely shouldn't use it. Shortcodes aren't meant to output anything, they should only return content.

    Here's a note from the codex on shortcodes:

    Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results.

    http://codex.wordpress.org/Function_Reference/add_shortcode#Notes

提交回复
热议问题