WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Wordpress and I want to show ** short content with limit ** of words for every post on home page and 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)}



It's showing content perfectly but when i use [gallery] short-code inside post editor, it only shows me the text rather than the gallery. this also causes issues when i am using vemio vedio tags because it strips my tags.

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.php ?

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
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.