0

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

0

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
        )
    );
1
  • 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
    Mar 6, 2022 at 0:16

Your Answer

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

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