Community Forums › Forums › Archived Forums › Design Tips and Tricks › Trying to restore tags to the excerpt, needing paragraphs to display correctly
Tagged: brad dalton, Excerpt, paragraph, replace, tags
- This topic has 3 replies, 2 voices, and was last updated 7 years, 7 months ago by David Borrink.
-
AuthorPosts
-
February 17, 2017 at 12:36 pm #201399David BorrinkParticipant
I tried Brad Dalton's code below to restore the stripped tags in front page excerpts. It restores tags, but if my excerpt has a tag that doesn't get closed before the excerpt cutoff point, then all the rest of my content on the page carries the tag. So if italics are in an excerpt but don't get closed off, then from that point on all the content in my page becomes italic.
// Add html to archive content limit. add_filter( 'get_the_content_limit_allowedtags', 'custom_get_the_content_limit_allowedtags' ); function custom_get_the_content_limit_allowedtags() { return '<script>,<style>,<strong>,<b>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>'; }
I tried adding <p> to the list of tags above to return, but that doesn't do anything because the "text" mode in the visual editor doesn't have <p> tags. Is there any way to get paragraphs to be separated?
We recently moved our site from a TwentyTwelve child theme to Genesis, and we had paragraph breaks show up in that theme in the excerpts using the following code. It doesn't work when we try it in Genesis. I don't understand most of this code so I'm not sure if it somehow can look at the text and determine if paragraph breaks are needed.
http://sallieborrink.comfunction 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, '<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');
February 17, 2017 at 1:15 pm #201404Victor FontModeratorThe function you are using to try to add paragraph tags is actually stripping tags. That's what this line of code does: $text = strip_tags($text, '<p>);
As for the text editor, you can just add paragraph tags manually.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?February 17, 2017 at 1:35 pm #201406David BorrinkParticipantI can see that it does strip the tags (the one I was trying).
I understand that I can add the paragraph tags manually, of course, but when I view my posts on a single post, there are separated paragraphs. How does the single post create those visual breaks when there are no <p> tags in the actual post in the text editor?
Also, why does Brad's code not allow for the tags to close automatically at the end of the excerpt, and prevent the same tag from continuing down the page?
February 18, 2017 at 4:47 pm #201474David BorrinkParticipantI've done some reading on how function wpautop is supposed to add <p> tags around paragraphs that have double line breaks. That explains why there are no <p> tags in the text editor. So it puts those tags in for single posts.
I'd like to get the <p> tags to work in excerpts, but I'm not seeing a way to figure that out. I've read through the formatting.php file and found the wpautop section, but it's extremely cryptic for me with all it's characters that obviously mean certain types of content setups. Too many slashes and brackets to understand.
The WordPress reference at https://codex.wordpress.org/Function_Reference/wpautop says that wpautop filters the_excerpt. Okay, but shouldn't that mean that it makes the excerpt contain <p> tags? It's not doing that. Is this a flaw with the Genesis Sample theme? I'm not sure what to do here.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.