0

I want to display text from content (only text) with the formating (paragraph, bold, italic.) on loop. When I am using this code:

<?php echo mb_substr( strip_tags( get_the_excerpt() ),0,255); ?>

or

<?php the_excerpt(); ?>

The text displayed without the text formating. No p, br even the hr is disappear.

When I am using this code:

<?php echo apply_filters('the_content',substr(get_the_content(),0,550)); ?>

The text displayed with the format, but the other content also display (image, video and else) I just want to display the text with the format.

Anybody know how to resolve the problem? Really appreciate for any help

Thank you

  • I think (could be wrong) you will find here your answer. – Charles Feb 20 '16 at 16:47
  • @charles : thank you. It's look like similar to what I need. – Mailmulah Feb 20 '16 at 18:31
0

Try this code in your theme's functions.php file-

function filtered_content($content){
    $content = preg_replace("/<img[^>]+\>/i", "", $content); // removes images
    $content = preg_replace('/<iframe.*?>/', "", $content); // removes iframes
    return $content;
}
add_filter('the_content', 'filtered_content');

This will remove img and iframe tag from your content. Then use the_content() in your template.

  • thank you. I tried and work fine. But unfortunately, affect to other look which use the_content(). Will check then. – Mailmulah Feb 20 '16 at 18:33

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.