I am creating some blog pages with example codes, and I would like to show the codes in excerpts, but WordPress automatically excludes code blocks from excerpts, is there a workaround for showing code blocks in the excerpt?
1 Answer
Try getting it in raw form from the DB:
global $wpdb;
$post_excerpt = $wpdb->get_var(
$wpdb->prepare(
"SELECT post_excerpt FROM $wpdb->posts
WHERE ID = %d
",
$post->ID
)
);
-
That's assuming WordPress is putting the code blocks into post_excerpt but just filtering them out when reading it from the DB. I'd expect it's the other way around, code isn't written into post_excerpt in the first place.– RupMar 6, 2022 at 0:16