## plugins – Is there a way to cache the_content or specific pages body in WordPress?

Question

There are some pages that I want to be in a transient. I’m making a plugin, so I don’t want to edit any theme files. Most of the page is built with a builder and have some includes or shortcodes with extra queries, the most heavy pages does not change that often.

What did I try so far ?

I will do a separate cache fragment for header, body and footer. At the moment I want to cache the body/the_content, the problem is that I can’t cache it with the shortcodes executed/rendered.

function cache_the_content( $content ) { if ( is_page() ) {$transient = get_transient( 'cache_'.'page_'.get_queried_object_id() );

if( false === $transient ) { set_transient( 'cache_'.'page_'.get_queried_object_id(),$content, YEAR_IN_SECONDS );
}

}

return \$content;
}