{"id":887,"date":"2020-01-30T05:37:31","date_gmt":"2020-01-30T05:37:31","guid":{"rendered":"http:\/\/shaplakanon.com\/wpsupport\/?p=887"},"modified":"2020-02-10T09:21:25","modified_gmt":"2020-02-10T09:21:25","slug":"wordpress-filter-function-to-modify-final-html-output","status":"publish","type":"post","link":"https:\/\/shaplakanon.com\/wpsupport\/wordpress-filter-function-to-modify-final-html-output\/","title":{"rendered":"WordPress filter function to modify final html output"},"content":{"rendered":"\n
WordPress has great filter support for getting at all sorts of specific bits of content and modifying it before output. Like\u00a0 WordPress also have action hook that fires just before PHP shuts down execution.<\/p>\n\n\n\n By adding function to this action hook, it is possible to change anything. The following will code work.<\/p>\n\n\n\n The code go to functions.php in your theme’s file.<\/p>\n\n\n\n If you need any help with code, feel free to comment below.<\/p>\n","protected":false},"excerpt":{"rendered":" WordPress has great filter support for getting at all sorts of specific bits of content and modifying it before output.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[228,227],"class_list":["post-887","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-shutdown-hook-wordpress","tag-wordpress-action-hook"],"yoast_head":"\nthe_content<\/code>\u00a0filter, which lets you access the markup for a post before it’s output to the screen. <\/p>\n\n\n\n
do_action( 'shutdown' )\n\n<\/pre>\n\n\n\n
rs the entire WP process, capturing the final output for manipulation.\n *\/\n\nob_start();\n\nadd_action('shutdown', function() {\n $final = '';\n\n \/\/ We'll need to get the number of ob levels we're in, so that we can iterate over each, collecting\n \/\/ that buffer's output into the final output.\n $levels = ob_get_level();\n\n for ($i = 0; $i < $levels; $i++) {\n $final .= ob_get_clean();\n }\n\n \/\/ Apply any filters to the final output\n echo str_replace('foo', 'bar', $final);\n}, 0);<\/pre>\n\n\n\n