How to debug the output from within WordPress filters

WordPress has a great actions and filters system allowing you to create injection points for modifying parts of your code (especially for plugin authors). However, you probably arrived here because you’re trying to echo or print_r something from within a filter and not seeing the output.

Because WordPress operates on a post/redirect approach, it means you’re not seeing the output because the page has been reloaded. You need to kill the script from within your filter callback function to see the output.

add\_filter('sh\_pre\_process\_body', function($body, $assets\_path, $article\_file) {
	$load\_file = file\_get\_contents($article\_file);
  
  	echo $assets\_path;
  
  	die;

	return shand\_fix\_content\_paths($assets\_path, $load\_file);
}, 10, 3);

By using die you will be able to see the output or other equivalents that kill script execution. However, the result will mean your site will break until you remove this script killer.