2016-07-22 44 views
1

我试图创建一个额外的简码内的格式显示the_content返回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]简码,它的小部件,而不是上面添加在小部件内部。

任何帮助,非常感谢。

回答

0

,请返回

apply_filters('the_content',the_content()); 

这将实现内容的内容。

+0

即使不工作。内容正在返回就好。我认为问题在于使用文本小部件“echo”中的代码。 – kiarashi

1

找到了解决办法,这要归功于TRS:

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

    return $content;