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 1


Try getting it in raw form from the DB:

global $wpdb;
$post_excerpt = $wpdb->get_var(
            "SELECT post_excerpt FROM $wpdb->posts
             WHERE ID = %d
  • 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.
    – Rup
    Commented Mar 6, 2022 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.