使用短代码中的格式返回the_content()

时间:2016-07-22 10:05:56

标签: php wordpress widget shortcode

我正在尝试创建一个额外的短代码以显示the_content

function custom_recipe_content( $atts ){                
    if ( ! is_singular( 'recipe' ) ) {
        return;
    }               
    return the_content();           
}
add_shortcode( 'recipe_content', 'custom_recipe_content' );

当我在wp文本小部件中添加[recipe_content]短代码时,它被添加到小部件上方而不是小部件内部。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

找到解决方案,感谢TRS:

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

    return $content;

答案 1 :(得分:0)

尝试返回

apply_filters('the_content',the_content());

这会将内容实现为内容。

相关问题