Community Forums › Forums › Archived Forums › Design Tips and Tricks › Code added to restore excerpt tags controls my excerpt length
Tagged: get_the_content_limit
- This topic has 8 replies, 2 voices, and was last updated 5 years, 11 months ago by Brad Dalton.
-
AuthorPosts
-
April 20, 2018 at 7:08 pm #219160David BorrinkParticipant
I found this code to allow tags on the excerpts on the front page. It brings back all the tags I want in my content, but with two critical problems explained below after the code.
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>,<strong>'; } 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' );
1) No matter what I set my character limit to on the Archive Settings on the Genesis Settings page, it remains unchanged. My character count looks to be about 250-300 when I use the code below. If I remove this code it becomes whatever I choose in the Genesis settings.
2) I cannot get the paragraphs to break into separate paragraphs like a single post. I have the
<p>
tag specified, but it's not taking. I want to be able to show the flow of my posts with separate paragraph as they are in the single posts, and not have them all run together. How can I get that? What is stripped out on the front page so that I know what I could put back in to get what I want?I currently do not have this code running on my site.
http://aquietsimplelife.comApril 29, 2018 at 3:49 am #219390Brad DaltonParticipantHello David
What you can do if you want to display content with HTML tags in excerpts is add the HTML to the Excerpt meta box. Based on my testing this works however it only works when using the Genesis > Content Archives > Display > Entry Excerpts. It won't work if using the Entry Content option.
Anything else and you might need custom code written to do exactly what you want.
April 29, 2018 at 5:27 am #219395Brad DaltonParticipantIf you prefer to allow HTML tags in the excerpt without having to use manual excerpts, based on my testing, this solution works https://wordpress.stackexchange.com/a/141136
Again, this only works when using the Genesis > Content Archives > Display > Entry Excerpts option.
April 29, 2018 at 5:31 am #219396Brad DaltonParticipantIf you are using the Genesis > Content Archives > Display > Entry Content option, this code enables the use of HTML tags in the content limit on archives.
April 29, 2018 at 5:39 am #219397Brad DaltonParticipantYou can then use this code to modify the read more link however this code only works when using the Genesis > Content Archives > Display > Entry Content option.
April 29, 2018 at 5:44 am #219398Brad DaltonParticipantBased on my testing, the 2nd and 3rd code snippets you posted do nothing when using Genesis > Content Archives > Display > Entry Content option. Only the 1st snippet ( which came from my site ) works when using this option.
Not sure where you got snippets 2 & 3 however i wouldn't suggest using them with Genesis. as there's genesis specific functions you can use to limit the content when using the Genesis > Content Archives > Display > Entry Content option.
April 29, 2018 at 5:56 am #219399Brad DaltonParticipantWhen using the Genesis > Content Archives > Display > Entry Excerpts option you can modify the following value in this code snippet to control the excerpt length
$excerpt_word_count = 75;
April 30, 2018 at 4:29 pm #219447David BorrinkParticipantHi Brad, thanks for all your information. I put only this code in and tried it,
add_filter( 'get_the_content_limit_allowedtags', 'get_the_content_limit_custom_allowedtags' ); function get_the_content_limit_custom_allowedtags() { // Add custom tags to this string return '<script>,<style>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>,<p>,<strong>'; }
and set the Genesis > Content Archives > Display > Entry Content option to Entry Content with a 1000 for the moment. There are shorter-than-1000 posts on the front page, but the longer ones appear to have the length okay. I haven't tried the other code yet regarding excerpt length.
I see a lot of my tags are showing up now, bolds, italics, links, and it looks like they're closing properly at the moment. What I don't understand is why
<p>
doesn't work, even though it's specced in the code. That's the one I want to really fix so the shortened "excerpt" starts to read like the actual post.May 4, 2018 at 5:46 am #219538Brad DaltonParticipantAnother option is to use the get_the_content_limit filter located on line 85 of formatting.php
return apply_filters( 'get_the_content_limit', $output, $content, $link, $max_characters );
You can use this filter to change the value for the $content variable so the content limit includes p tags.
One way to do this would be to use the_content rather than get_the_content however there is probably other methods you can use.
Based on my testing this enables p tags when using the content limit.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.