I feel like I’m time traveling back to the good old days of Mother Blogs.
Jim posted on Mastodon1 about wanting to be able to display the WP excerpt on posts syndicated via Feed WordPress in a Noir-themed #DS106 course he’s teaching. It broke my heart to hear he was doing it by hand. I had a busy couple of days so I didn’t get to this until this morning but I put in a quick 14 minutes2
Alan has some other ways to make this work that I missed but I really wanted to do something WP-related and not AI so . . .
So to make this work, we wanted to only apply it to posts in the “film noir” category and only in archive view. A later addition was to keep the first image in the post.
function ds_noir_chopper($content){
// Only run filter on single posts in main query
if (has_category('Tech Noir') || has_category('tech-noir') && is_archive()) {
preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $image);//img?
if($image){
$image = $image[0];//if img, first img
} else {
$image = '';
}
$content = $image . get_the_excerpt();
return $content;
}
else {
return $content;
}
}
add_filter('the_content', 'ds_noir_chopper', 200);
This is a clever way, the best part of the stuff is multiple routes to the same end. Yours is better because I forgot the TwentyTwelve does not do mu ch with featured image (I think). But you are right, it was good to dust off some WP chops and poke in the templates.
But I said nothing about AI, blechhh.
I was just trying to abide by the ancient rule of “never touch the source code in the main files.”
On another site, I did find it odd that if you’re using the Gute editor the content filter doesn’t work the same way. Poor WP. 🙁