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?
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?
Share Improve this question asked Mar 4, 2022 at 9:34 Botond VajnaBotond Vajna 4714 silver badges11 bronze badges1 Answer
Reset to default 0Try 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
)
);