Community Forums › Forums › Archived Forums › Design Tips and Tricks › Putting tags back in excerpts, works in one of three "identical" sites
Tagged: Excerpt, html tags, paragraphs
- This topic has 2 replies, 2 voices, and was last updated 7 years, 10 months ago by David Borrink.
-
AuthorPosts
-
March 27, 2017 at 6:53 am #203850David BorrinkParticipant
I have a function to put tags back into the excepts on my front page. I’ve put this in three sites that are using the same basic theme, based on Genesis Sample.
Here is the function. You’ll see the paragraph and link tags specified in the eighth line.
function my_custom_excerpt($text) { global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace('\]\]\>', ']]>', $text); $fulltext = str_replace('\]\]\>', ']]>', $text); $text = strip_tags($text, '<em><p><a>'); $excerpt_length = 100; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '... <a href="'. esc_url( get_permalink() ) . '">Read more ยป</a>'); $text = implode(' ', $words); } else { $text = $fulltext; } } return $text; } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'my_custom_excerpt');
Site #1 was developed first. The code is not working on the excerpts.
Site #2 and #3 were made from tweaks of Site #1. It’s the same basic design, as you’ll notice if you take the links.
Site #2 also has the code not working.
Site #3 is the site where the function is working correctly. This baffles me. I’ve looked into plug-ins as a possible culprit, #1 has a lot, #2 has many, and #3 not so much. I tried turning #2’s plugins off one by one to see if that would be the reason to allow the function to work. But no success.
I look at the HTML and #3’s content clearly has <p> and <br> tags in it. Does anyone have any insight what I could do to determine why #3 is working, so that I can fix #1 and #2?
Thanks.
http://aquietsimplelife.comMarch 27, 2017 at 7:10 am #203890Victor FontModeratorAre all three sites displaying excerpts and not content limited text? There's a different filter for content limited text.
There's also a much simpler way to add tags back in. You've written a lot of code, when you only need a couple of lines: https://wpsites.net/wordpress-tips/add-back-html-tags-stripped-from-content-limit-excerpts-in-wordpress/
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?March 27, 2017 at 12:04 pm #203901David BorrinkParticipantYes, I'm doing content limited excerpts for this. I had used that code you suggested, and over the weekend I worked with someone to solve the closed tags issue. So that post you linked to now has an update. I have returned to that code again.
I have put it on all three sites, but site #3 is now going down, being merged into #2. So we're now dealing with #1 and #2 only.
The code shows the italics and the links like I want, but the paragraph and break tags are not working. Brad's code doesn't have
<p>
tags, so I added them.I also added a function via another user to put the "read more" back into the situation.
There's a new consequence. The number of characters setting in the Genesis Settings panel is not having an effect.
Here is the complete set of code I added....
add_filter( 'get_the_content_limit_allowedtags', 'get_the_content_limit_custom_allowedtags' ); /** * @author Brad Dalton * @example http://wp.me/p1lTu0-a5w */ function get_the_content_limit_custom_allowedtags() { // Add custom tags to this string return '<script>,<style>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>,<p>'; } add_filter( 'the_content_limit', 'force_balance_tags_content_limit' ); function force_balance_tags_content_limit( $content ) { $content = force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( $content ) ) ) ); return $content; } function yourprefix_read_more_for_content_limit( $content ) { return $content . '<p><a class="more-link" href="' . get_permalink() . '">[Continue Reading]</a></p>'; } add_filter( 'the_content_limit', 'yourprefix_read_more_for_content_limit' );
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.