-
AuthorPosts
-
September 8, 2014 at 4:32 pm #101002
Kevin LParticipantHello,
Currently, the blog index shows the excerpts of the posts with the formatting tags stripped. Is there an easy way to keep the formatting instead?
Cheers,
Kevin.September 8, 2014 at 5:22 pm #101032
DarshanaModeratorHi Kevin,
You can do that by copying the following code to your functions.php file which is in the root of your theme folder. Before doing so, we’re highly recommending for you to create a child theme setup for your website so that your custom code will be remain separately.
Please check our child theme setup guide at (http://theme.co/x/member/kb/how-to-setup-child-themes/).
Once you activate the Child Theme, open the functions.php and add the following code.
function custom_wp_trim_excerpt($text) { $raw_excerpt = $text; if ( '' == $text ) { //Retrieve the post content. $text = get_the_content(''); $text = strip_shortcodes( $text ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); // the code below sets the excerpt length to 55 words. You can adjust this number for your own blog. $excerpt_length = apply_filters('excerpt_length', 55); // the code below sets what appears at the end of the excerpt, in this case ... $excerpt_more = apply_filters('excerpt_more', ' ' . '...'); $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if ( count($words) > $excerpt_length ) { array_pop($words); $text = implode(' ', $words); $text = force_balance_tags( $text ); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'custom_wp_trim_excerpt');Hope that helps.
September 10, 2014 at 10:24 pm #102490
Kevin LParticipantThanks! You guys are awesome!
September 11, 2014 at 12:29 am #102530
Paul RModeratorYou’re welcome Kevin. 🙂
September 28, 2014 at 9:22 am #114155
Shannon MParticipantI tried this, but the excerpt length doesn’t appear to be working. I’m in the Integrity stack. Any ideas? Thank you.
September 28, 2014 at 9:39 am #114165
Shannon MParticipantDISREGARD. I’m just a ditz. I had the “full” version selected in my WP reading settings. Switched to excerpt and it’s perfect. Sorry!
September 28, 2014 at 3:46 pm #114270
RadModeratorOkay cool! No problem 🙂 Cheers.
February 25, 2016 at 10:24 pm #812948
edwinfuParticipantI used the code in my child theme which is fantastic. However, there is a line break before the ‘… Read More’ that I want to remove. Is there some way to do so?
Thank you
February 26, 2016 at 12:36 am #813117
Rue NelModeratorHello Edwin,
Thanks for updating this thread! To assist you better with this issue, would you mind providing us the url of your site with login credentials so we can take a closer look? This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.
To do this, you can make a post with the following info:
– Link to your site

– WordPress Admin username / passwordDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
Thank you.
February 26, 2016 at 4:31 pm #814039
edwinfuParticipantThis reply has been marked as private.February 27, 2016 at 2:20 am #814486
ChristopherModeratorHi there,
Please update your code to :
function custom_wp_trim_excerpt($text) { $raw_excerpt = $text; if ( '' == $text ) { //Retrieve the post content. $text = get_the_content(''); $text = strip_shortcodes( $text ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); // the code below sets the excerpt length to 55 words. You can adjust this number for your own blog. $excerpt_length = apply_filters('excerpt_length', 55); // the code below sets what appears at the end of the excerpt, in this case ... $excerpt_more = apply_filters('excerpt_more', ' ' . ' '); $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if ( count($words) > $excerpt_length ) { array_pop($words); $text = implode(' ', $words); $text = force_balance_tags( $text ); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'custom_wp_trim_excerpt'); Hope that helps.Hope it helps.
February 27, 2016 at 3:39 pm #814957
edwinfuParticipantIt didn’t work. Unfortunately, it didn’t seem like there was any change at all.
I’m looking for a solution that will remove the line break before the ‘…’. It should look as follows:
<category page post>…
<read more>February 28, 2016 at 12:21 am #815299
RadModeratorHi there,
Please try this one,
function custom_wp_trim_excerpt($text) { $raw_excerpt = $text; if ( '' == $text ) { //Retrieve the post content. $text = get_the_content(''); $text = strip_shortcodes( $text ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); // the code below sets the excerpt length to 55 words. You can adjust this number for your own blog. $excerpt_length = apply_filters('excerpt_length', 55); // the code below sets what appears at the end of the excerpt, in this case ... $excerpt_more = ''; $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if ( count($words) > $excerpt_length ) { array_pop($words); $text = implode(' ', $words); $text = force_balance_tags( $text ); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'custom_wp_trim_excerpt');Completely removing the excerpt more dots.
Please clear your caches before testing.
Cheers!
February 28, 2016 at 5:46 pm #815997
edwinfuParticipantI don’t want to completely remove the dots. I want to include the dots so that they appear without a line break after the cut-off at the excerpt.
February 28, 2016 at 9:15 pm #816169
Rue NelModeratorHello There,
Do you want something like this?

Please remove the code you have added and use this code instead:
// Custom Read More string // ============================================================================= function x_excerpt_string( $more ) { $stack = x_get_stack(); if ( $stack == 'integrity' ) { return ' ... <a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>'; } else if ( $stack == 'renew' ) { return ' ... <a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>'; } else if ( $stack == 'icon' ) { return ' ...'; } else if ( $stack == 'ethos' ) { return ' ...'; } } add_filter( 'excerpt_more', 'x_excerpt_string' ); // =============================================================================We would loved to know if this has work for you. Thank you.
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-101002 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
