Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #995713
    mtusa
    Participant

    When you search on our website, the results show what looks like code. (view picture below)
    How do we fix this?

    #995716
    mtusa
    Participant
    This reply has been marked as private.
    #995867
    Thai
    Moderator

    Hi There,

    Please add the following CSS under functions.php file locates in child theme:

    function x_allowedtags() {
      // Add custom tags to this string
      return '<script>,<style>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>,<p>,<img>,<video>,<audio>';
    }
    if ( ! function_exists( 'x_custom_wp_trim_excerpt' ) ) : 
    
        function x_custom_wp_trim_excerpt($wpse_excerpt) {
        global $post;
        $raw_excerpt = $wpse_excerpt;
            if ( '' == $wpse_excerpt ) {
    
                $wpse_excerpt = get_the_content('');
                $wpse_excerpt = strip_shortcodes( $wpse_excerpt );
                $wpse_excerpt = apply_filters('the_content', $wpse_excerpt);
                $wpse_excerpt = str_replace(']]>', ']]>', $wpse_excerpt);
                $wpse_excerpt = strip_tags($wpse_excerpt, x_allowedtags()); /*IF you need to allow just certain tags. Delete if all tags are allowed */
    
                //Set the excerpt word count and only break after sentence is complete.
                    $excerpt_word_count = 75;
                    $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);
                    $tokens = array();
                    $excerptOutput = '';
                    $count = 0;
    
                    // Divide the string into tokens; HTML tags, or words, followed by any whitespace
                    preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $wpse_excerpt, $tokens);
    
                    foreach ($tokens[0] as $token) { 
    
                        if ($count >= $excerpt_word_count && preg_match('/[\,\;\?\.\!]\s*$/uS', $token)) {
                        // Limit reached, continue until , ; ? . or ! occur at the end
                            $excerptOutput .= trim($token);
                            break;
                        }
    
                        // Add words to complete sentence
                        $count++;
    
                        // Append what's left of the token
                        $excerptOutput .= $token;
                    }
    
                $wpse_excerpt = trim(force_balance_tags($excerptOutput));
    
                    $excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . '&nbsp;&raquo;&nbsp;' . sprintf(__( 'Read more about: %s &nbsp;&raquo;', 'wpse' ), get_the_title()) . '</a>';
                    $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); 
    
                    //$pos = strrpos($wpse_excerpt, '</');
                    //if ($pos !== false)
                    // Inside last HTML tag
                    //$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */
                    //else
                    // After the content
                    $wpse_excerpt .= $excerpt_end; /*Add read more in new paragraph */
    
                return $wpse_excerpt;   
    
            }
            return apply_filters('wpse_custom_wp_trim_excerpt', $wpse_excerpt, $raw_excerpt);
        }
    
    endif; 
    
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'x_custom_wp_trim_excerpt');

    Hope it helps 🙂

    #1009149
    mtusa
    Participant

    For some reason, when I entered it in, it gives me an error. see below:
    Parse error: syntax error, unexpected ‘–‘ (T_DEC) in /home/content/p3pnexwpnas14_data01/13/3076913/html/wp-content/themes/x-child/functions.php on line 6

    Please advise.

    Thank you!

    #1009305
    Rupok
    Member

    Hi there,

    Can you post the complete code on your functions.php? I mean if you have any other code above the suggested code, we need to check that too. You can login with FTP and share the code with us. Meantime take off the suggested code to get rid of the error.

    Thanks

    #1009358
    mtusa
    Participant
    This reply has been marked as private.
    #1009554
    Rupok
    Member

    Hi there,

    It seems you have already posted it in a new thread. So it’s not really convenient to ask help for same issue on multiple thread. It might create conflict or waste the time double. We’ll assist you on this on the new thread.

    Hope this makes sense and consider this thread as closed.

    Thanks

  • <script> jQuery(function($){ $("#no-reply-995713 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>