WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Preserve HTML tags in the excerpt

[Resolved] Preserve HTML tags in the excerpt

  • Sandra
    Member

    @sandra-test

    I would like to preserve the html tags of my post.

    I’m not sure if i should change something in my own wordpress files or in your php file on line 380

    (i’m no php expert 🙂 )

    function rpwe_excerpt( $length ) {

    $excerpt = explode( ‘ ‘, get_the_excerpt(), $length );
    if ( count( $excerpt ) >= $length ) {
    array_pop( $excerpt );
    $excerpt = implode( ” “, $excerpt );
    } else {
    $excerpt = implode( ” “, $excerpt );
    }
    $excerpt = preg_replace( ‘\[[^\]]*\]‘, ”, $excerpt );

    return $excerpt;

    }

    http://wordpress.org/plugins/recent-posts-widget-extended/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Satrya
    Participant

    @satrya

    Hmmm.. it’s a bit complicated, why you need to display the html tag in excerpt?

    Sandra
    Member

    @sandra-test

    I’d like to have the same styling, paragraphs, use bold type as in the article.

    Satrya
    Participant

    @satrya

    I’m not sure this would be possible, because when you modify the excerpt code you can’t limit the exceprt words

    Sandra
    Member

    @sandra-test

    For my website i’d like to show to latest news post (one) on the homepage. Those news post are mostly short enough to fit in.
    I’ve changed line 116 into <div class=”rpwe-summary”><?php echo the_content( $length ); ?>
    Maybe i shouldn’t have (mis-)used this plugin. But now it works for me. But would be better if i’d known how to limit the content words 🙂

    Thank you for your time and your nice plugin.

    Satrya
    Participant

    @satrya

    Hi Sandra,
    I just found this http://wordpress.stackexchange.com/questions/37858/truncate-custom-post-type-content, try to change

    <div class="rpwe-summary"><?php echo the_content( $length ); ?>

    to

    <div class="rpwe-summary"><?php echo apply_filters( 'the_content', wp_trim_words( get_the_content(), 15, '…' ) ); ?>

    Change 15 to fit your needs

    Sandra
    Member

    @sandra-test

    wp_trim_words will also take strip out all the tags

    Satrya
    Participant

    @satrya

    Sorry, for late reply. Hmm.. I’m still searching what function can fit your needs.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Preserve HTML tags in the excerpt’ is closed to new replies.