Service excerpts not displaying hmtl elements like ul and li

How do I display html elements in the Service Excerpt tabs? I want it to display ALL html elements like <p>,

    and

  • .

  • Vaughan

    Hi @nicholas,

    I've been looking at this, in particular the function get_excerpt in appointments.php

    It uses the wordpress function; $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );

    which strips all tags. please be aware, that trimming content with html in extremely difficult and not quite as simple because if you cut off at say 50 words, you could inevitably leave html tags open without closing them which would mess up the whole page/template, this is one reason why html is stripped from excerpts in wordpress.will

    I'm not exactly sure of how to achieve this with apps+ but you would definitely run into this issue so I wouldn't recommend it.

    Let me just ask one of our developers to see if he can come up with a filter for it.

    Thanks

  • Jose

    Hi @Nicholas,

    Hope you are doing well today :slight_smile:

    As @Vaughan pointed above, there is a big chance to break the markup by stripping some closing tags out.

    With that warning, and if you still feel that it wouldn't be a problem for you, then you can override the excerpt by using the following hook:

    function get_custom_excerpt( $excerpt, $page_id, $worker_id=0 ) {
        $text = '';
        if ( !$page_id )
            return $text;
        $page = get_post( $page_id );
        if ( !$page )
            return $text;
    
        $thumb = preg_match('/<img[^>]+\>/i', $excerpt , $matches) ? $matches[0]: '';
        $text = $page->post_content;
    
        $text = strip_shortcodes( $text );
    
        $text = apply_filters('app_the_content', $text, $page_id, $worker_id );
        $text = str_replace(']]>', ']]>', $text);
        $excerpt_length = apply_filters('app_excerpt_length', 55);
        $excerpt_more = apply_filters('app_excerpt_more', ' &hellip; <a href="'. esc_url( get_permalink($page->ID) ) . '" target="_blank">' . __( 'More information <span class="meta-nav">&rarr;</span>', 'appointments' ) . '</a>');
    
        if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
            $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
            preg_match_all( '/./u', $text, $words_array );
            $words_array = array_slice( $words_array[0], 0, $excerpt_length + 1 );
            $sep = '';
        } else {
            $words_array = preg_split( "/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY );
            $sep = ' ';
        }
        if ( count( $words_array ) > $excerpt_length ) {
            array_pop( $words_array );
            $text = implode( $sep, $words_array );
            $text = $text . $excerpt_more;
        } else {
            $text = implode( $sep, $words_array );
        }
    
        $custom_excerpt = $thumb . $text;
    
        return $custom_excerpt;
    }
    
    add_filter( 'app_excerpt', 'get_custom_excerpt', 20, 3 );

    Hope this helps.

    Just let me know if you have any question with regard to this customization.

    Cheers!
    Jose