Walrus
Walrus

Reputation: 20484

Wordress filter the entire content including the template and structure from body

Wordpress has a hook for filtering the content of a post or page;

add_filter('the_content' fn() => // something);

This filters the post content and allows us to modify it / manipulate the DOM etc..

However, it relates only to the output of $post->post_content and therefore does not allow anything to be manipulated before then. Whilst much of what happens before then can be manipulated from the template there are still two HTML elements Wordpress will add anyway after the opening body tag. The first is a div with class "wp-site-blocks" and the second "entry-content".

Is there a hook or similar that would allow the entire content from the opening body tag to be manipulated at the server level.

Something like:

add_filter('full_post_body_content');

Upvotes: 0

Views: 45

Answers (1)

If you are doing it from the child theme, you may want to replace the template. for example copy your current - single-post.php (or for custom post type "single-{custom-post-type}.php") and replace those elements, easiest way actually.

Other solution you may try - ob_start() on 'wp_head' them ob_get_clean() in the 'wp_footer'.

Upvotes: 1

Related Questions