Php 返回在短代码中包含格式的\u content()

Php 返回在短代码中包含格式的\u content(),php,wordpress,widget,shortcode,Php,Wordpress,Widget,Shortcode,我正试图创建一个额外的短代码来显示内容 function custom_recipe_content( $atts ){ if ( ! is_singular( 'recipe' ) ) { return; } return the_content(); } add_shortcode( 'recipe_content', 'custom_recipe_content' )

我正试图创建一个额外的短代码来显示内容

function custom_recipe_content( $atts ){                
    if ( ! is_singular( 'recipe' ) ) {
        return;
    }               
    return the_content();           
}
add_shortcode( 'recipe_content', 'custom_recipe_content' );
当我在wp文本小部件中添加
[recipe\u content]
短代码时,它被添加到小部件的上方,而不是小部件的内部

非常感谢您的帮助。

请尝试返回

apply_filters('the_content',the_content());

这将以内容的形式实现内容。

由于TRS,找到了解决方案:

$content = apply_filters( 'the_content', get_the_content(), get_the_ID() );

    return $content;

即使这样也不行。返回的内容很好。我认为问题在于文本小部件中的代码,
echo
正在被使用。