Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using wordpress I want to show ** short content with limit ** of wordsfor every post on home page for this I am using this code


function abc_the_content($num_words) {

$get_the_content = get_the_content();
$striptag_from_content = strip_tags($get_the_content);
echo $content = wp_trim_words($striptag_from_content, $num_words = $num_words, $more = null)}



Its showing content perfectly but when I am using


shortcode inside post editor its showing me same as text rather then showing gallery.THis is also issue in if i am using vemio vedio tag because its strip my tag.

I just want to strip image tag from editor not any other tag like vemio.or gallery short code How i can modify my function

PLease provide me your valuable answer



share|improve this question
Your function is too limited for what you want it to do. A better suggestion is to re-use an existing function for the job, there is one in core to do the job. –  hakre Nov 10 '12 at 8:43

1 Answer 1

function abc_the_content($num_words) {
    global $post;
    $content = $post->post_content;
    $content = strip_tags($content);
    $content = wp_trim_words($content, $num_words, $more = null);
    echo apply_filters('the_content', $content);

change the strip tags line to this one if you want to strip out only the img tag

    $content = preg_replace("/<\/?img(.|\s)*?>/i", '', $content);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.