Wordpress has great filter support for getting at all sorts of specific bits of content and modifying it before output. Like "the_content" filter, which lets you access the markup for a post before it's output to the screen.
I'm trying to find a catch-all filter that gives me one last crack at modifying the final markup in its entirety before output. Anyone know of one?
I've browsed the list of filters a number of times, but nothing jumps out at me: http://adambrown.info/p/wp_hooks/hook/filters
(I've tapped some Wordpress-specific communities for this question, but not having received a single reply, thought I'd turn to the venerable SO.)
@jacer, if you use the following hooks, the header.php also gets included.
I was using the top solution of this post (by kfriend) for a while. It uses an
mu-plugin
to buffer the whole output.But this solution breaks the caching of
wp-super-cache
and no supercache-files are generated when i upload themu-plugin
.So: If you are using
wp-super-cache
, you can use the filter of this plugin like this:I have run into problems with this code, as I end up with what seems to be the original source for the page so that some plugins has no effect on the page. I am trying to solve this now - I havnt found much info regarding best practises for collecting the output from wordpress.
Update and sollution:
The code from KFRIEND didnt work for me as this captures unprocessed source from wordpress, not the same output that ends up in the browser infact. My sollution is probably not elegant using a globals variable to buffer up the contents - but atleast I know get the same collected HTML as is delivered to the browser. Could be that different setups of plugins creates problems but thanks to code example by Jacer Omri above I ended up with this.
This code is in my case located typically in functions.php in theme folder.
Modified https://stackoverflow.com/users/419673/kfriend answer.
All code will be on functions.php. You can do whatever you want with the html on the "final_output" filter.
On your theme's 'functions.php'