Community Forums › Forums › Archived Forums › Design Tips and Tricks › HTML in Excerpt almost figured out
- This topic has 12 replies, 2 voices, and was last updated 6 years, 9 months ago by sunnypapabear.
-
AuthorPosts
-
August 2, 2017 at 11:44 am #209914sunnypapabearMember
I've been trying to get HTML formatting to show up in Excerpts, in Widgets, and found the below Function code that actually works really well. The only issue is that it has a problem with links (it puts the following text on the next line). To see what I mean please go to http://PeterCruikshank.com/dev/ (development site) and look at the lower left Widget entitled Latest. If you click on the "More News" you will see that the original page of information looks fine. If anybody has a suggestion on how to edit the below to handle the attribute correctly I would appreciate it.
// Preserve HTML in Excerpt
http://petercruikshank.com/dev
function custom_wp_trim_excerpt($text) {
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = apply_filters('excerpt_length', 80);
$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 = $text . $excerpt_more;
$text = force_balance_tags( $text );
} 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');August 2, 2017 at 11:48 am #209915Victor FontModeratorYou're over thinking this. All you need to add HTML back to excerpts is this:
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>,<span>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>'; }
Add whatever tags you want to the return line.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 3, 2017 at 7:29 am #209926sunnypapabearMemberI replaced the code with what you sent, but if you look at the Front Page again, none of the HTML Links, Italics or other HTML appear (see http://www.petercruikshank.com/dev/news/ashes-of-the-dragon-coming-soon/ to see the Page the Excerpt comes from). This is the Post (actually News post) that I am using to create the Page where the Excerpt is drawing upon.
The Novella, Ashes of the Dragon, is due to be released soon. This short book is another story set in the world of Athule. While it is part of the Dragon-Called series, it is not the long awaited third book in the series. It is a mild divergence from the main story line--a new set of characters that have not been seen in the first two books, Fire of the Covenant and Betrayal of the Covenant. I wrote this originally as a story, separate from the series, but as I continued to write it I saw a connection between the novella and the series. What this means is that it is possible that some of these new characters may find their way into a future book of the Dragon-Called series main story line.
August 3, 2017 at 8:00 am #209944Victor FontModeratorUse content limit excerpts in Genesis.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 3, 2017 at 11:12 am #209946sunnypapabearMemberOkay I went in and changed to Display Entry Concepts (see below image), but still didn't change how anything is displayed.
August 3, 2017 at 2:11 pm #209955Victor FontModeratorChange display to content limit.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?August 3, 2017 at 2:22 pm #209956sunnypapabearMemberThe other option was Entry Content which was what it was before I changed it. Am I in the wrong section altogether and should be changing something else?
August 4, 2017 at 8:03 pm #210012sunnypapabearMemberVictor, can you PLEASE provide a bit more detailed information so I can resolve this issue? I would REALLY appreciate it.
August 4, 2017 at 8:56 pm #210015sunnypapabearMemberThe original code I had put into the theme function.php (the one you stated was way too complicated) preserved most of the HTML (see image below). However, "unwanted" returns are displayed before and after the HTML. Additionally, "The Novella," at the beginning of the excerpt is NOT included within the yet displays as a Link.
When I use the code you provided, none of the HTML is displayed at all. Your code is currently what I have in the theme function.php. You mentioned changing a couple of settings, but I evidently don't know what I'm doing, because whatever I did (which was probably not what you meant) and nothing changed.
If you can instruct me in exactly what I need to do to get your code working OR if you can tell me what to fix in the original code to take care of the "unwanted" returns and the incorrectly Linked "The Novella," I would be EXTREMELY happy. Thanks for taking the time to help me figure this out. It is the last thing I need to fix before I take my revised website live.
August 4, 2017 at 8:57 pm #210017sunnypapabearMemberThe original code I had put into the theme function.php (the one you stated was way too complicated) preserved most of the HTML (see image below). However, "unwanted" returns are displayed before and after the HTML. Additionally, "The Novella," at the beginning of the excerpt is NOT included within the yet displays as a Link.
When I use the code you provided, none of the HTML is displayed at all. Your code is currently what I have in the theme function.php. You mentioned changing a couple of settings, but I evidently don't know what I'm doing, because whatever I did (which was probably not what you meant) and nothing changed.
If you can instruct me in exactly what I need to do to get your code working OR if you can tell me what to fix in the original code to take care of the "unwanted" returns and the incorrectly Linked "The Novella," I would be EXTREMELY happy. Thanks for taking the time to help me figure this out. It is the last thing I need to fix before I take my revised website live.
August 4, 2017 at 10:46 pm #210019sunnypapabearMemberVictor. When I use the original code, the one you stated was way too complicated, most of the HTML is preserved in the excerpt (See below image). However, there is an "unwanted return" before and after each Link and at the beginning of the excerpt, "The Novella," is displayed as a link even though it is NOT included within the Link for "Ashes of the Dragon".
When I use the code you provided me, none of the HTML is displayed (I have your code currently in the theme function.php). I know the problem may be that I don't understand what else you want me to do.
So if you could either explain to me, possibly in greater detail, what I need to do to make the code you provided, work--something I need to do to the code or something I need to change in my site settings--OR, if you could tell me how to fix the original code to get rid of the "unwanted returns" and fix the issue with "The Novella," being displayed as link, I would be EXTREMELY appreciative. This is the last issue I need to resolve before taking the redevelopment of my website live. Thanks for all the effort you've put out to help me with this issue.
August 6, 2017 at 10:20 am #210014sunnypapabearMemberVictor when I use the code you provided, none of the HTML formatting is displayed--but I'm not sure what else you wanted me to do to fix it. Right now I have your code in the function.php and not my original code.
When I use the original code I had, that was much more extensive, I did get most of the HTML formatting, but with some issues. Below is what is displayed when I use the original code. You can see that unwanted returns have been inserted before and after the HTML. Additionally, "The Novella," was NOT included within the but shows as a link. After the below image I have included the actual code that is creating the page where the excerpt is being created from. So if I can get make whatever setting or other changes I need to make the code you gave me work OR if I can figure out what was wrong with the original code that is causing the problems with the "unwanted" return and also prevent "The Novella," from being made into a Link.
The Novella, Ashes of the Dragon, is due to be released soon. This short book is another story set in the world of Athule. While it is part of the Dragon-Called series, it is not the long awaited third book in the series. It is a mild divergence from the main story line--a new set of characters that have not been seen in the first two books, Fire of the Covenant and Betrayal of the Covenant. I wrote this originally as a story, separate from the series, but as I continued to write it I saw a connection between the novella and the series. What this means is that it is possible that some of these new characters may find their way into a future book of the Dragon-Called series main story line.
August 6, 2017 at 7:34 pm #210061sunnypapabearMemberI got some input from WordPress.org forum that resolved the issue. Thank you for all your support.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.