Feb. 17th, 2023

solarbird: (vision)

WordPress’s default post excerpting is very, very stupid, and breaks HTML all the way back to 1.0 by ignoring newlines as whitespace. It’s terrible in other ways as well.

These are notes on how to fix that. There’s a very easy way, and varyingly easy ways to make custom code to do it your own way. I went with the very easy way because it is basically … hm. I’d say “exactly what I would have written” except it’s more capable and does some things I wouldn’t’ve bothered to do.

I think the most important thing I learned is that plugin function redefinitions override core function definitions even for your styles. This is in fact how you’re supposed to do that. Or you can do it in your style’s functions.php but unless you want it specific to one particular style it’s best to do it as a plugin.

Also there’s also a tool to make the plugin method even easier.


Key links:

EASIEST FIX:
There is an existing plugin! – https://wordpress.org/plugins/advanced-excerpt/

ON WRITING YOUR OWN – it’s not too hard:
https://wordpress.stackexchange.com/questions/141125/allow-html-in-excerpt/141136#141136

A PLUGIN TO MAKE WRITING YOUR OWN PLUGIN CODE TRIVIAL:
https://wordpress.org/plugins/code-snippets/


Helpful notes from Mastodon:

@cyberia@mast.eu.org helpfully said:

@moira Hi! If I understand your problem correctly, I guess you will have no choice but to overwrite the function rendering the excerpt ultimately.

Here is a proof of concept that should render what you expect – https://rentry.co/get_the_excerpt

[CODE COPIED FROM LINK]

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', function ($excerpt) {
global $post;
$excerpt = get_the_content('');
$excerpt = apply_filters('the_content', $excerpt);
$excerpt = strip_tags($excerpt, '<br>');
$excerpt = substr($excerpt, 0, 250);
return $excerpt;

});

[END CODE]

Full Disclaimer: please note that it is not suitable for production websites as it does not handle all situations! Bugs are to be expected with that. It’s only the path to follow imho…


@phoopee3@phpc.social helpfully said:

@moira @cyberia The best way to approach this is either, like you said, add code to your theme’s functions.php file, or to write a simple plugin for your site. With either of those approaches you would want to add a function to listen to the get_the_excerpt hook. A quick search online came up with this SO solution –

https://wordpress.stackexchange.com/questions/141125/allow-html-in-excerpt/141136#141136

I also found this plugin which might be the easiest solution if you don’t want to write code

https://wordpress.org/plugins/advanced-excerpt/


And @cyberia@mast.eu.org helpfully said:

You can add the snippet I wrote into your theme’s (or even better, your child theme’s) functions.php, or use a plugin like Code Snippets for a hassle-free, 30-second solution –

https://wordpress.org/plugins/code-snippets/

Feel free to let me know if you need any help!

Posted via Solarbird{y|z|yz}.

solarbird: (korra-on-the-air)

I guess it’s time to roll this back out; welcome to today’s Cultural Warfare Update, since the Republican Party is determined to make everything an existential cultural war with the direct intent of exterminating me and mine, and I don’t mean that metaphorically.

The GOP are still a Party of Plague as Idaho Republican lawmakers introduce a bill to criminalise COVID-19 vaccination. Yep: if they have their way, vaccination will be a crime.

DeSantis and the Florida GOP are trying to move the state away from the SAT and ACT scores to a new system “focused on ‘Western tradition’” which means “classical and Christian tradition” which means Christian Fundamentalist horseshit. The unfortunately-acronymed “CLT” is fashioned specifically to their needs and desires, and focuses very heavily on Christian sources for literature and philosophy, and DeSantis’s GOP are working to make it the critical test for all Florida schools, including universities.

Meanwhile, actually in Florida, here’s the state of yet another school library as their book-banning programme continues apace.

Law Dork provides a legislative roundup as GOP-controlled states continue to try to legislate LGBT people, particularly trans kids, out of existence. Utah and South Dakota had already passed bills banning health care for trans kids; Utah added a second bill making life even more difficult for trans children. Several states have had single houses pass bans so far, several making gender-affirming care for trans kids a felony.

Other bills are aimed at supporting refusal-of-service to LGBT people in general. As I said, Law Dork has the details.

In other political news, Dominion Voting Systems have the texts, and solid proof that nobody at Fox News believed the lies they were shoving out on television. Here’s CBS’s report; here’s NPR’s. Nothing about it should be surprising but the depth, breadth, and contemptuousness of their lies are worth recording. Hopefully this trial will make that matter.

Back in the day, I was doing these at least weekly. I’m not sure how often I’ll be doing these now, but it is a record year for anti-LGBT bills in state legislatures, so that’s amazing. I suspect they’ll be out fairly often. If you’re seeing this on Dreamwidth, which most of you are (have, a link if you’re not), hit the “culture war” tag to see some history. It goes back pretty far. Not to the beginning, mind you; but pretty far.

Posted via Solarbird{y|z|yz}.

September 2025

S M T W T F S
 123456
789101112 13
14151617 18 1920
21 2223 24252627
282930    

Most Popular Tags