Wordpress using echo vs return in shortcode function

后端 未结 6 2068
我在风中等你
我在风中等你 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:18

    If you use "echo" in the shortcode, the information will show up wherever the shortcode is processed, which isn't necessarily where you actually added the shortcode. If you use "return", the information will return exactly where you added the shortcode within the page.

    For example, if you have an image, then shortcode, then text:
    Echo: will output above the image
    Return: will output after the image and before the text (where you actually added the shortcode)

提交回复
热议问题