0

i'm using this function in my Wordpress index:

<?php echo get_the_excerpt(); ?>

But if the article contains an image in the first 50 words, I get the link of the image in this form:

Immagine: http://i.imgur.com/UUsXR3w.jpg

How can I exclude images from the excerpt?

  • You are wrong. Here's the excerpt view, and here's where the image is. – Mayeenul Islam Nov 23 '15 at 10:15
  • 1
    According with the codex, only manual excerpt can contains some allowed HTML because it is returned unchanged by get_the_excerpt(). Instead, if the excerpt is auto generated, all tags are removed, including images. Can you check that the excerpt if not manually created? Can you post the real code you are using? – cybmeta Nov 23 '15 at 10:15
  • Please look if this helps wordpress.stackexchange.com/questions/61475/… – jas Nov 23 '15 at 10:34
2

You may try the following code.

   $content = get_the_excerpt();
   $content = preg_replace("/<img(.*?)>/si", "", $content);
   echo $content; 

preg_replace will remove the image tag content from the post content.

2

If you definitely want to show the excerpt from your content, and not from defined excerpt, you can use:

echo wp_trim_words( get_the_content(), 55, '&hellip;' );

Resources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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