I’m trying to return a function that is essentially an echo. Other than adding “$output = …” in front of each line and return $output or using an output buffer like ob_clean(), is there any other way to make this function able to be returned and not echo’d? This is in WordPress, so would there be any WP filters or actions to make it work?
Here’s an example of what the function kind of looks like (it’s much longer).
<?php function app($args = '') { ?>
<script type="text/javascript">
$(document).ready(function() {
//do some stuff
});
</script>
<div><?php echo $args ?></div>
<?php } ?>
Solved with creating a class for everything.