I want to run a javascript function when the add_attachment hook fires. The following code does not interfere with uploading an image.
add_action('add_attachment', function( $post_ID ) {
?>
<?php
});
When I add script tags and console.log("x"); I get an error message. The error message says "Bei dem Upload ist ein Fehler aufgetreten. Bitte versuche es später nochmal." See picture.
add_action('add_attachment', function( $post_ID ) {
?>
<script type="text/javascript">
console.log("x");
</script>
<?php
});
How can I avoid the error message and validate that my javascript code runs?