Wordpress using echo vs return in shortcode function

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

    I would use:

    function foobar_shortcode($atts) {
        return "Foo Bar"; //so does this
    }
    

    It is easier when you're doing things like:

    $output = '
    ' . do_shortcode('foobar') . '
    '; echo $ouput;

    Later on..

提交回复
热议问题