Easy way is use – excerpt()
else you can also use wp_trim_words( get_the_content(), 40, '...' );
In a excerpt()
, You have to add content on excerpt in backend. While wp_trim_words
will trim words from content.
In sidebar case you have to add shortcode into functions.php file which uses in sidebar widget(if you are using widgets).
function test_short(){
ob_start();
global $post;
echo wp_trim_words( get_the_content($post->ID), 40, '...' );
return ob_get_clean();
}
add_shortcode('test_short', 'test_short');